<?php

namespace MathPHP\Tests\LinearAlgebra\Decomposition;

use MathPHP\LinearAlgebra\MatrixFactory;
use MathPHP\Exception;
use MathPHP\Tests\LinearAlgebra\Fixture\MatrixDataProvider;

class HessenbergTest extends \PHPUnit\Framework\TestCase
{
    use MatrixDataProvider;

    /**
     * @test         Hessenberg decomposition property A = QHQ*
     * @dataProvider dataProviderForHessenbergDecomposition
     * @dataProvider dataProviderForSquareMatrix
     * @dataProvider dataProviderForNonsingularMatrix
     * @param        array $A
     * @throws       \Exception
     */
    public function testHessenbergDecompositionPropertyAEqualsQHQTranspose(array $A)
    {
        // Given
        $A = MatrixFactory::create($A);

        // When
        $hessenberg = $A->hessenbergDecomposition();
        $QHQᵀ = $hessenberg->Q->multiply($hessenberg->H)->multiply($hessenberg->Q->transpose());

        // Then A = QHQ*
        $this->assertEqualsWithDelta($A->getMatrix(), $QHQᵀ->getMatrix(), 0.0001);
    }

    /**
     * @test         Hessenberg decomposition properties - Q is orthogonal and H is upper Hessenberg
     * @dataProvider dataProviderForHessenbergDecomposition
     * @dataProvider dataProviderForSquareMatrix
     * @dataProvider dataProviderForNonsingularMatrix
     * @param        array $A
     * @throws       \Exception
     */
    public function testHessenbergDecompositionProperties(array $A)
    {
        // Given
        $A = MatrixFactory::create($A);

        // When
        $hessenberg = $A->hessenbergDecomposition();

        // Then
        $this->assertTrue($hessenberg->Q->isOrthogonal());
        $this->assertTrue($hessenberg->H->isUpperHessenberg());
    }

    /**
     * @test         Orthogonal matrix Q has the property Q*Q = I
     * @dataProvider dataProviderForHessenbergDecomposition
     * @dataProvider dataProviderForSquareMatrix
     * @dataProvider dataProviderForNonsingularMatrix
     * @param        array $A
     * @throws       \Exception
     */
    public function testHessenbergDecompositionOrthogonalMatrixQProperty(array $A)
    {
        // Given
        $A = MatrixFactory::create($A);
        $I = MatrixFactory::identity($A->getN());

        // When
        $hessenberg = $A->hessenbergDecomposition();
        $QᵀQ = $hessenberg->Q->transpose()->multiply($hessenberg->Q);

        // Then Q*Q = I
        $this->assertEqualsWithDelta($I->getMatrix(), $QᵀQ->getMatrix(), 0.0001);
    }

    /**
     * @test         Hessenberg form preserves eigenvalues
     * @dataProvider dataProviderForHessenbergDecomposition
     * @dataProvider dataProviderForSquareMatrix
     * @dataProvider dataProviderForNonsingularMatrix
     * @param        array $A
     * @throws       \Exception
     */
    public function testHessenbergDecompositionPreservesTrace(array $A)
    {
        // Given
        $A = MatrixFactory::create($A);

        // When
        $hessenberg = $A->hessenbergDecomposition();

        // Then trace(A) = trace(H) since similarity transformations preserve trace
        $this->assertEqualsWithDelta($A->trace(), $hessenberg->H->trace(), 0.0001);
    }

    /**
     * @test         Hessenberg decomposition on already Hessenberg matrix maintains structure
     * @dataProvider dataProviderForUpperHessenbergMatrix
     * @param        array $A
     * @throws       \Exception
     */
    public function testHessenbergDecompositionOfHessenbergMatrix(array $A)
    {
        // Given an already upper Hessenberg matrix
        $originalH = MatrixFactory::create($A);

        // When
        $hessenberg = $originalH->hessenbergDecomposition();

        // Then the result should still be in Hessenberg form
        $this->assertTrue($hessenberg->H->isUpperHessenberg());

        // And Q should be orthogonal
        $this->assertTrue($hessenberg->Q->isOrthogonal());

        // And reconstruction should work
        $QHQᵀ = $hessenberg->Q->multiply($hessenberg->H)->multiply($hessenberg->Q->transpose());
        $this->assertEqualsWithDelta($originalH->getMatrix(), $QHQᵀ->getMatrix(), 0.01);
    }

    /**
     * @test   Hessenberg decomposition exception for non-square matrix
     * @throws \Exception
     */
    public function testHessenbergDecompositionExceptionNotSquare()
    {
        // Given
        $A = MatrixFactory::create([
            [1, 2, 3],
            [2, 3, 4],
        ]);

        // Then
        $this->expectException(Exception\MatrixException::class);

        // When
        $A->hessenbergDecomposition();
    }

    /**
     * @test   Hessenberg decomposition invalid property
     * @throws \Exception
     */
    public function testHessenbergDecompositionInvalidProperty()
    {
        // Given
        $A = MatrixFactory::create([
            [4, 1, 2],
            [1, 3, 1],
            [2, 1, 2],
        ]);
        $hessenberg = $A->hessenbergDecomposition();

        // Then
        $this->expectException(Exception\MatrixException::class);

        // When
        $doesNotExist = $hessenberg->doesNotExist;
    }

    /**
     * @test         Hessenberg decomposition preserves determinant: det(A) = det(H)
     * @dataProvider dataProviderForHessenbergDecomposition
     * @dataProvider dataProviderForSquareMatrix
     * @dataProvider dataProviderForNonsingularMatrix
     * @param        array $A
     * @throws       \Exception
     */
    public function testHessenbergDecompositionPreservesDeterminant(array $A)
    {
        // Given
        $A = MatrixFactory::create($A);

        // When
        $hessenberg = $A->hessenbergDecomposition();

        // Then det(A) = det(H) since similarity transformations preserve determinant
        $this->assertEqualsWithDelta($A->det(), $hessenberg->H->det(), 0.0001);
    }

    /**
     * @test         Hessenberg decomposition of symmetric matrix produces tridiagonal form
     * @dataProvider dataProviderForSymmetricMatrix
     * @param        array $A
     * @throws       \Exception
     */
    public function testHessenbergDecompositionSymmetricMatrixTridiagonal(array $A)
    {
        // Given
        $A = MatrixFactory::create($A);

        // When
        $hessenberg = $A->hessenbergDecomposition();

        // Then H should be tridiagonal (upper Hessenberg + symmetric = tridiagonal)
        $this->assertTrue($hessenberg->H->isTridiagonal());

        // And the result should still maintain the fundamental decomposition property
        $QHQᵀ = $hessenberg->Q->multiply($hessenberg->H)->multiply($hessenberg->Q->transpose());
        $this->assertEqualsWithDelta($A->getMatrix(), $QHQᵀ->getMatrix(), 0.0001);
    }

    /**
     * @test         Hessenberg decomposition of identity matrix: Q=I, H=I
     * @dataProvider dataProviderForIdentityMatrix
     * @param        array $A
     * @throws       \Exception
     */
    public function testHessenbergDecompositionIdentityMatrix(array $A)
    {
        // Given
        $A = MatrixFactory::create($A);
        $I = MatrixFactory::identity($A->getN());

        // When
        $hessenberg = $A->hessenbergDecomposition();

        // Then Q should be identity and H should be identity
        $this->assertEqualsWithDelta($I->getMatrix(), $hessenberg->Q->getMatrix(), 0.0001);
        $this->assertEqualsWithDelta($I->getMatrix(), $hessenberg->H->getMatrix(), 0.0001);
    }

    /**
     * @test         Hessenberg decomposition preserves Frobenius norm: ||A||_F = ||H||_F
     * @dataProvider dataProviderForHessenbergDecomposition
     * @dataProvider dataProviderForSquareMatrix
     * @dataProvider dataProviderForNonsingularMatrix
     * @param        array $A
     * @throws       \Exception
     */
    public function testHessenbergDecompositionPreservesFrobeniusNorm(array $A)
    {
        // Given
        $A = MatrixFactory::create($A);

        // When
        $hessenberg = $A->hessenbergDecomposition();

        // Then ||A||_F = ||H||_F since similarity transformations preserve norms
        $this->assertEqualsWithDelta($A->frobeniusNorm(), $hessenberg->H->frobeniusNorm(), 0.0001);
    }

    /**
     * @test         Hessenberg decomposition backward error bound: numerican stability test
     * @dataProvider dataProviderForSquareMatrix
     * @dataProvider dataProviderForNonsingularMatrix
     * @param        array $A
     * @throws       \Exception
     */
    public function testHessenbergDecompositionBackwardError(array $A)
    {
        // Given
        $A = MatrixFactory::create($A);

        // When
        $hessenberg = $A->hessenbergDecomposition();
        $QHQᵀ = $hessenberg->Q->multiply($hessenberg->H)->multiply($hessenberg->Q->transpose());

        // Calculate backward error: ||A - QHQ^T||_F / ||A||_F
        $error = $A->subtract($QHQᵀ);
        $relativeError = $error->frobeniusNorm() / $A->frobeniusNorm();

        // Then backward error should be small (indicating numerical stability)
        $this->assertLessThan(1e-10, $relativeError);
    }

    /**
     * @test         Hessenberg decomposition of zero matrix: Q=I, H=0
     * @dataProvider dataProviderForZeroMatrix
     * @param        array $A
     * @throws       \Exception
     */
    public function testHessenbergDecompositionZeroMatrix(array $A)
    {
        // Given
        $A = MatrixFactory::create($A);
        $I = MatrixFactory::identity($A->getN());
        $Z = MatrixFactory::zero($A->getN(), $A->getN());

        // When
        $hessenberg = $A->hessenbergDecomposition();

        // Then Q should be identity and H should be zero
        $this->assertEqualsWithDelta($I->getMatrix(), $hessenberg->Q->getMatrix(), 0.0001);
        $this->assertEqualsWithDelta($Z->getMatrix(), $hessenberg->H->getMatrix(), 0.0001);
    }

    /**
     * @test         Hessenberg decomposition property A = QHQ*
     * @dataProvider dataProviderForHessenbergDecomposition
     */
    public function testHessenbergDecomposition(array $A, array $H, array $Q)
    {
        // Given
        $A = MatrixFactory::create($A);

        // When
        $hessenberg = $A->hessenbergDecomposition();

        // Then
        $this->assertEqualsWithDelta($H, $hessenberg->H->getMatrix(), 0.00001);
        $this->assertEqualsWithDelta($Q, $hessenberg->Q->getMatrix(), 0.00001);
    }

    /**
     * Test cases produced with Python scipy.linalg: H, Q = hessenberg(A, calc_q=True)
     * @return array
     */
    public function dataProviderForHessenbergDecomposition(): array
    {
        return [
            [
                [
                    [2, 5, 8, 7],
                    [5, 2, 2, 8],
                    [7, 5, 6, 6],
                    [5, 4, 4, 8]
                ],
                [
                    [2, -11.65843866, 1.42005301, 0.25349066],
                    [-9.94987437, 14.53535354, -5.31022304, 2.43081618],
                    [0, -1.83299243, 0.38969961, -0.51527034],
                    [0, 0, -3.83189513, 1.07494686],
                ],
                [
                    [1, 0, 0, 0],
                    [0, -0.50251891, -0.47575099, -0.72189732],
                    [0, -0.70352647, -0.26030613, 0.66127999],
                    [0, -0.50251891, 0.84017957, -0.20389466],
                ]
            ],
            [
                [
                    [3, 2, 1, -2, -5],
                    [4, 2, 1, 0, 3],
                    [4, 4, 0, 1, -1],
                    [5, 6, 7, -2, 4],
                    [6, 7, 1, 2, -1]
                ],
                [
                    [3, 2.90346475, -0.55297768, -4.78764119, -1.53055545],
                    [-9.64365076, 7.80645161, 2.87800175, 5.1085876, 5.58042269],
                    [0, -3.45402388, -6.11922963, -0.23472002, 1.4679321],
                    [0, 0, 1.40413625, -1.71582362, -0.9870602],
                    [0, 0, 0, -2.66812895, -0.97139836],
                ],
                [
                    [1, 0, 0, 0, 0],
                    [0, -0.41478068, -0.03680062, -0.40477686, -0.81409975],
                    [0, -0.41478068, -0.48712395, -0.56923092, 0.51637526],
                    [0, -0.51847585, 0.80961356, -0.07484492, 0.26477711],
                    [0, -0.62217102, -0.32539492, 0.71170928, -0.0221646],
                ]
            ],
            [
                [
                    [4, 2, 1, -2, -5],
                    [4, 2, 1, 0, 3],
                    [4, 4, 0, 1, -1],
                    [5, 6, 7, -2, 4],
                    [6, 7, 1, 2, -1]
                ],
                [
                    [4, 2.90346475, -0.55297768, -4.78764119, -1.53055545],
                    [-9.64365076, 7.80645161, 2.87800175, 5.1085876, 5.58042269],
                    [0, -3.45402388, -6.11922963, -0.23472002, 1.4679321],
                    [0, 0, 1.40413625, -1.71582362, -0.9870602],
                    [0, 0, 0, -2.66812895, -0.97139836],
                ],
                [
                    [1, 0, 0, 0, 0],
                    [0, -0.41478068, -0.03680062, -0.40477686, -0.81409975],
                    [0, -0.41478068, -0.48712395, -0.56923092, 0.51637526],
                    [0, -0.51847585, 0.80961356, -0.07484492, 0.26477711],
                    [0, -0.62217102, -0.32539492, 0.71170928, -0.0221646],
                ]
            ],
            [
                [
                    [0],
                ],
                [
                    [0],
                ],
                [
                    [1],
                ]
            ],
            [
                [
                    [1],
                ],
                [
                    [1],
                ],
                [
                    [1],
                ]
            ],
            [
                [
                    [-1],
                ],
                [
                    [-1],
                ],
                [
                    [1],
                ]
            ],
            [
                [
                    [2],
                ],
                [
                    [2],
                ],
                [
                    [1],
                ]
            ],
            [
                [
                    [-2],
                ],
                [
                    [-2],
                ],
                [
                    [1],
                ]
            ],
            [
                [
                    [9],
                ],
                [
                    [9],
                ],
                [
                    [1],
                ]
            ],
            [
                [
                    [1, 0],
                    [0, 1]
                ],
                [
                    [1, 0],
                    [0, 1],
                ],
                [
                    [1, 0],
                    [0, 1],
                ]
            ],
            [
                [
                    [3, 8],
                    [4, 6]
                ],
                [
                    [3, 8],
                    [4, 6],
                ],
                [
                    [1, 0],
                    [0, 1],
                ]
            ],
            [
                [
                    [6, 1, 1],
                    [4, -2, 5],
                    [2, 8, 7],
                ],
                [
                    [6, -1.34164079, 0.4472136],
                    [-4.4721360, 5, -6],
                    [0, -9, 0],
                ],
                [
                    [1, 0, 0],
                    [0, -0.89442719, -0.4472136],
                    [0, -0.4472136, 0.89442719],
                ]
            ],
            [
                [
                    [1, 2, 0],
                    [-1, 1, 1],
                    [1, 2, 3],
                ],
                [
                    [1, -1.41421356, 1.41421356],
                    [1.41421356, 0.5, 1.5],
                    [0, 0.5, 3.5],
                ],
                [
                    [1, 0, 0],
                    [0, -0.70710678, 0.70710678],
                    [0, 0.70710678, 0.70710678],
                ]
            ],
            [
                [
                    [4, 6, 3, 2],
                    [3, 6, 5, 3],
                    [5, 7, 8, 6],
                    [5, 4, 3, 2],
                ],
                [
                    [4, -5.59812317, -2.40919832, -3.44336759],
                    [-7.68114575, 13.79661017, 3.6577976, 3.21587642],
                    [0, 5.49816506, 1.07168784, 0.49378626],
                    [0, 0, 1.01454191, 1.13170199],
                ],
                [
                    [1, 0, 0, 0],
                    [0, -0.39056673, -0.39330574, -0.83232699],
                    [0, -0.65094455, -0.52133077, 0.55180197],
                    [0, -0.65094455, 0.75731422, -0.05240577],
                ]
            ],
            [
                [
                    [3, 2, 0, 1],
                    [4, 0, 1, 2],
                    [3, 0, 2, 1],
                    [9, 2, 3, 1],
                ],
                [
                    [3, -1.65118597, -0.98374612, -1.14272853],
                    [-10.29563014, 3.4245283, 2.05003765, -1.95326254],
                    [0, 0.96591059, -1.30958029, -0.68836863],
                    [0, 0, -0.59124004, 0.88505199],
                ],
                [
                    [1, 0, 0, 0],
                    [0, -0.38851434, -0.73425216, -0.5567139],
                    [0, -0.29138576, -0.47527175, 0.83018739],
                    [0, -0.87415728, 0.48475821, -0.02930073],
                ]
            ],
            [
                [
                    [1, 2, 3, 4],
                    [5, 6, 7, 8],
                    [2, 6, 4, 8],
                    [3, 1, 1, 2],
                ],
                [
                    [1, -4.54219979, -0.07572127, 2.89183114],
                    [-6.164414, 13.23684211, 0.21832202, -5.90507625],
                    [0, 7.21633458, -0.83030993, -2.37051194],
                    [0, 0, 1.52280217, -0.40653218],
                ],
                [
                    [1, 0, 0, 0],
                    [0, -0.81110711, -0.0408185, -0.5834716],
                    [0, -0.32444284, -0.79862281, 0.50689096],
                    [0, -0.48666426, 0.60044604, 0.63452537],
                ]
            ],
            [
                [
                    [7, 4, 2, 0],
                    [6, 3, -1, 2],
                    [4, 6, 2, 5],
                    [8, 2, -7, 1],
                ],
                [
                    [7, -2.97112541, -2.0642847, -2.62890518],
                    [-10.77032961, 3.89655172, -5.72402015, 4.47029221],
                    [0, 7.34539418, 2.81430864, 0.14745624],
                    [0, 0, 1.63301895, -0.71086037],
                ],
                [
                    [1, 0, 0, 0],
                    [0, -0.55708601, -0.08368722, -0.82622734],
                    [0, -0.37139068, -0.86476792, 0.33800209],
                    [0, -0.74278135, 0.49514937, 0.45066946],
                ]
            ],
            [
                [
                    [-4, 3, 1, 5, -8],
                    [6, 0, 9, 2, 6],
                    [-1, 4, 4, 0, 2],
                    [8, -1, 3, 4, 0],
                    [5, 9, -7, -7, 1],
                ],
                [
                    [-4, -1.51448037, -3.10434083, 6.88988309, -6.29276793],
                    [-11.22497216, 3.38095238, 3.61134778, 2.37332483, -1.82297254],
                    [0, 3.40134694, 7.25536671, 5.52668611, -0.04012002],
                    [0, 0, -2.66559339, -9.32396678, -8.93526512],
                    [0, 0, 0, 1.35477604, 7.68764769],
                ],
                [
                    [1, 0, 0, 0, 0],
                    [0, -0.53452248, -0.43777567, 0.54961657, 0.46963795],
                    [0, 0.08908708, -0.87430411, -0.42581453, -0.21526219],
                    [0, -0.71269665, 0.10601405, -0.01633564, -0.69322266],
                    [0, -0.4454354, 0.1808475, -0.71856576, 0.50253828],
                ]
            ],
            [
                [
                    [4, 3, 1, 5, -8],
                    [6, 0, 9, 2, 6],
                    [-1, 4, 4, 0, 2],
                    [8, -1, 3, 4, 0],
                    [5, 9, -7, -7, 1],
                ],
                [
                    [4, -1.51448037, -3.10434083, 6.88988309, -6.29276793],
                    [-11.22497216, 3.38095238, 3.61134778, 2.37332483, -1.82297254],
                    [0, 3.40134694, 7.25536671, 5.52668611, -0.04012002],
                    [0, 0, -2.66559339, -9.32396678, -8.93526512],
                    [0, 0, 0, 1.35477604, 7.68764769],
                ],
                [
                    [1, 0, 0, 0, 0],
                    [0, -0.53452248, -0.43777567, 0.54961657, 0.46963795],
                    [0, 0.08908708, -0.87430411, -0.42581453, -0.21526219],
                    [0, -0.71269665, 0.10601405, -0.01633564, -0.69322266],
                    [0, -0.4454354, 0.1808475, -0.71856576, 0.50253828],
                ]
            ],
            [
                [
                    [4, 3, 1, 5, 8],
                    [6, 0, 9, 2, 6],
                    [-1, 4, 4, 0, 2],
                    [8, -1, 3, 4, 0],
                    [5, 9, -7, -7, 1],
                ],
                [
                    [4, -8.64144682, -0.21078088, -4.60716914, 1.74784461],
                    [-11.22497216, 3.38095238, 3.61134778, 2.37332483, -1.82297254],
                    [0, 3.40134694, 7.25536671, 5.52668611, -0.04012002],
                    [0, 0, -2.66559339, -9.32396678, -8.93526512],
                    [0, 0, 0, 1.35477604, 7.68764769],
                ],
                [
                    [1, 0, 0, 0, 0],
                    [0, -0.53452248, -0.43777567, 0.54961657, 0.46963795],
                    [0, 0.08908708, -0.87430411, -0.42581453, -0.21526219],
                    [0, -0.71269665, 0.10601405, -0.01633564, -0.69322266],
                    [0, -0.4454354, 0.1808475, -0.71856576, 0.50253828],
                ]
            ],
            [
                [
                    [4, 3, 1, 5, 8],
                    [6, 0, 9, 2, 6],
                    [1, 4, 4, 0, 2],
                    [8, -1, 3, 4, 0],
                    [5, 9, -7, -7, 1],
                ],
                [
                    [4, -8.81962098, 2.7109019, -3.49120902, 1.29489619],
                    [-11.22497216, 4.6031746, 2.5239909, 3.95015442, -1.73983039],
                    [0, 4.59136416, 3.11017801, 9.24540404, 5.69619695],
                    [0, 0, 2.08784622, -4.34800533, -10.48257431],
                    [0, 0, 0, -1.79822376, 5.63465271],
                ],
                [
                    [1, 0, 0, 0, 0],
                    [0, -0.53452248, -0.53127764, 0.29613973, 0.58679728],
                    [0, -0.08908708, -0.64800473, -0.68418667, -0.32255537],
                    [0, -0.71269665, 0.15183761, 0.24964087, -0.63772115],
                    [0, -0.4454354, 0.52419394, -0.61795574, 0.38070819],
                ]
            ],
            [
                [
                    [4, 3, 1, 5, 8],
                    [6, 0, 9, 2, 6],
                    [1, 4, 4, 0, 2],
                    [8, 1, 3, 4, 0],
                    [5, 9, -7, -7, 1],
                ],
                [
                    [4, -8.81962098, 3.07880928, -1.15715948, 3.22431404],
                    [-11.22497216, 5.36507937, 2.63635247, -0.42659013, -4.76639387],
                    [0, 4.48914595, 3.40715918, 10.74347447, -3.97262375],
                    [0, 0, 1.2461769, -4.82255566, 2.69801404],
                    [0, 0, 0, 9.15450427, 5.05031712],
                ],
                [
                    [1, 0, 0, 0, 0],
                    [0, -0.53452248, -0.45265489, 0.69757948, 0.15090437],
                    [0, -0.08908708, -0.64763985, -0.59080076, 0.47284309],
                    [0, -0.71269665, 0.03811499, -0.39645957, -0.57743446],
                    [0, -0.4454354, 0.61172986, -0.08459992, 0.64824126],
                ]
            ],
            [
                [
                    [4, 3, 1, 5, 8],
                    [6, 0, 9, 2, 6],
                    [1, 4, 4, 0, 2],
                    [8, 1, 3, 4, 0],
                    [5, 9, 7, -7, 1],
                ],
                [
                    [4, -8.81962098, 2.2922027, 3.95950597, 0.53141789],
                    [-11.22497216, 5.92063492, 8.24623555, -6.56257087, -1.90377959],
                    [0, 3.8143488, -0.25074437, -2.75856113, -4.22297172],
                    [0, 0, -7.98190988, 5.91655373, -6.95931234],
                    [0, 0, 0, -4.40005379, -2.58644429],
                ],
                [
                    [1, 0, 0, 0, 0],
                    [0, -0.53452248, -0.45488157, -0.07454354, -0.70838671],
                    [0, -0.08908708, -0.7492385, 0.42020266, 0.50411792],
                    [0, -0.71269665, 0.14866138, -0.47687695, 0.49249534],
                    [0, -0.4454354, 0.45784738, 0.76841483, -0.03875208],
                ]
            ],
            [
                [
                    [4, 3, 1, 5, 8],
                    [6, 0, 9, 2, 6],
                    [1, 4, 4, 0, 2],
                    [8, 1, 3, 4, 0],
                    [5, 9, 7, 7, 1],
                ],
                [
                    [4, -8.81962098, -4.13294816, -1.97354073, 0.48801865],
                    [-11.22497216, 10.36507937, 2.60225145, -3.2893321, 8.57954731],
                    [0, 7.71373047, -0.11384293, -6.0666409, 2.29981731],
                    [0, 0, -6.92153205, -0.33593031, -3.1645053],
                    [0, 0, 0, -1.97100376, -0.91530613],
                ],
                [
                    [1, 0, 0, 0, 0],
                    [0, -0.53452248, 0.08304394, 0.77533026, 0.32596381],
                    [0, -0.08908708, -0.31916002, 0.34239333, -0.87918552],
                    [0, -0.71269665, 0.48414797, -0.42936859, -0.27075237],
                    [0, -0.4454354, -0.81045748, -0.31188524, 0.21788432],
                ]
            ],
            [
                [
                    [2, -9, 1, 8, 4],
                    [-10, -1, 2, 7, 0],
                    [0, 4, -6, 1, -8],
                    [6, -14, 11, 0, 3],
                    [5, 1, -3, 2, -1],
                ],
                [
                    [2, 12.45214442, 1.68791816, 0.13785011, -2.01891778],
                    [12.68857754, 2.45341615, -7.2185007, 0.81096246, 0.40822462],
                    [0, 13.93081856, -9.50405636, -2.7023918, -8.83299682],
                    [0, 0, -6.27866554, -2.90326468, 0.12519887],
                    [0, 0, 0, -5.62548986, 1.9539049],
                ],
                [
                    [1, 0, 0, 0, 0],
                    [0, -0.78811041, 0.43297792, -0.43178739, -0.07051066],
                    [0, 0, -0.41864137, -0.27864835, -0.86434628],
                    [0, 0.47286624, 0.79360546, -0.00477779, -0.38283817],
                    [0, 0.3940552, -0.0863707, -0.85784143, 0.31838448],
                ]
            ],
            [
                [
                    [2, 9, 1, 8, 4],
                    [-10, -1, 2, 7, 0],
                    [0, 4, -6, 1, -8],
                    [6, -14, 11, 0, 3],
                    [5, 1, -3, 2, -1],
                ],
                [
                    [2, -1.73384289, 9.48152081, -7.63432292, -3.28810973],
                    [12.68857754, 2.45341615, -7.2185007, 0.81096246, 0.40822462],
                    [0, 13.93081856, -9.50405636, -2.7023918, -8.83299682],
                    [0, 0, -6.27866554, -2.90326468, 0.12519887],
                    [0, 0, 0, -5.62548986, 1.9539049],
                ],
                [
                    [1, 0, 0, 0, 0],
                    [0, -0.78811041, 0.43297792, -0.43178739, -0.07051066],
                    [0, 0, -0.41864137, -0.27864835, -0.86434628],
                    [0, 0.47286624, 0.79360546, -0.00477779, -0.38283817],
                    [0, 0.3940552, -0.0863707, -0.85784143, 0.31838448],
                ]
            ],
            [
                [
                    [2, 9, 1, 8, 4],
                    [10, -1, 2, 7, 0],
                    [0, 4, -6, 1, -8],
                    [6, -14, 11, 0, 3],
                    [5, 1, -3, 2, -1],
                ],
                [
                    [2, -12.45214442, 2.35001651, -1.07164695, 0.52258453],
                    [-12.68857754, -2.14285714, -8.00402806, 1.05139287, -7.1797514],
                    [0, 10.04174958, 0.9894645, -0.52351079, 12.9289077],
                    [0, 0, -1.87269811, 2.7805112, 4.09274735],
                    [0, 0, 0, -0.87904221, -9.62711855],
                ],
                [
                    [1, 0, 0, 0, 0],
                    [0, -0.78811041, -0.41932546, -0.31662352, -0.32062078],
                    [0, 0, -0.04709003, -0.67926365, 0.73238202],
                    [0, -0.47286624, 0.880135, -0.02367493, 0.03463228],
                    [0, -0.3940552, -0.21751107, 0.66165696, 0.59968283],
                ]
            ],
            [
                [
                    [2, 9, 1, 8, 4],
                    [10, 1, 2, 7, 0],
                    [0, 4, -6, 1, -8],
                    [6, -14, 11, 0, 3],
                    [5, 1, -3, 2, -1],
                ],
                [
                    [2, -12.45214442, 2.3196191, -1.06427036, 0.65634991],
                    [-12.68857754, -0.90062112, -7.5692877, 0.49553986, -6.58273768],
                    [0, 10.72624052, 1.87522904, 2.5411979, 12.59871066],
                    [0, 0, -1.38387233, 3.10582836, 0.86879839],
                    [0, 0, 0, -3.55409271, -10.08043628],
                ],
                [
                    [1, 0, 0, 0, 0],
                    [0, -0.78811041, -0.44824307, -0.35396718, -0.22949373],
                    [0, 0, -0.04408499, -0.50358185, 0.86282202],
                    [0, -0.47286624, 0.87873349, -0.06460042, 0.00719426],
                    [0, -0.3940552, -0.15799405, 0.78545486, 0.45035435],
                ]
            ],
            [
                [
                    [276, 1, 179, 23, 9387],
                    [0, 0, 78, 0, 0],
                    [0, 0, -1, 0, 1],
                    [0, 0, 1994, -1, 1089],
                    [1, 0, 212, 726, -378],
                ],
                [
                    [276, -9387, -23.1643612, 3.20061556, -178.952978],
                    [-1, -378, 726.194368, -4.95964599, 211.275039],
                    [0, 1089.00046, 0.831036105, -46.795883, 1993.44913],
                    [0, 0, 0.0716450466, -1.83158687, 78.023429],
                    [0, 0, 0, 0.0234619027, -0.999449236],
                ],
                [
                    [1, 0, 0, 0, 0],
                    [0, 0, 0, -0.99972458, -0.0234683663],
                    [0, 0, -0.000918273258, 0.0234683564, -0.999724158],
                    [0, 0, -0.999999578, -0.0000215503732, 0.000918020348],
                    [0, -1, 0, 0, 0],
                ]
            ],
            [
                [
                    [276, 1, 179, 23, 9387],
                    [0, 0, 78, 0, 0],
                    [0, 0, 1, 0, 1],
                    [0, 0, 1994, -1, 1089],
                    [1, 0, 212, 726, -378],
                ],
                [
                    [276, -9387, -23.1643612, 1.3876976, 178.976218],
                    [-1, -378, 726.194368, -0.457785422, -211.332748],
                    [0, 1089.00046, 0.831037792, -4.31935925, -1993.99548],
                    [0, 0, -0.0716254822, 0.168957516, 77.9978009],
                    [0, 0, 0, -0.00216617291, -0.999995308],
                ],
                [
                    [1, 0, 0, 0, 0],
                    [0, 0, 0, 0.999997654, -0.00216617799],
                    [0, 0, -0.000918273258, 0.00216617708, 0.999997232],
                    [0, 0, -0.999999578, -0.00000198914332, -0.000918271104],
                    [0, -1, 0, 0, 0],
                ]
            ],
            [
                [
                    [276, 1, 179, 23, 9387],
                    [0, 0, 78, 0, 0],
                    [0, 0, 1, 0, 1],
                    [0, 0, 1994, 1, 1089],
                    [1, 0, 212, 726, -378],
                ],
                [
                    [276, -9387, -23.1643612, 3.20061556, -178.952978],
                    [-1, -378, 726.194368, -4.95964599, 211.275039],
                    [0, 1089.00046, 2.83103611, -46.795883, 1993.44913],
                    [0, 0, 0.0716450466, -1.83048534, 77.9765052],
                    [0, 0, 0, -0.0234619027, 0.999449236],
                ],
                [
                    [1, 0, 0, 0, 0],
                    [0, 0, 0, -0.99972458, -0.0234683663],
                    [0, 0, -0.000918273258, 0.0234683564, -0.999724158],
                    [0, 0, -0.999999578, -0.0000215503732, 0.000918020348],
                    [0, -1, 0, 0, 0],
                ]
            ],
            [
                [
                    [276, 1, 179, 23, 9387],
                    [0, 0, 78, 0, 0],
                    [0, 0, 1, 0, 1],
                    [0, 0, 1994, 1, 1089],
                    [1, 0, 212, 726, 378],
                ],
                [
                    [276, -9387, -23.1643612, 3.20061556, -178.952978],
                    [-1, 378, 726.194368, -4.95964599, 211.275039],
                    [0, 1089.00046, 2.83103611, -46.795883, 1993.44913],
                    [0, 0, 0.0716450466, -1.83048534, 77.9765052],
                    [0, 0, 0, -0.0234619027, 0.999449236],
                ],
                [
                    [1, 0, 0, 0, 0],
                    [0, 0, 0, -0.99972458, -0.0234683663],
                    [0, 0, -0.000918273258, 0.0234683564, -0.999724158],
                    [0, 0, -0.999999578, -0.0000215503732, 0.000918020348],
                    [0, -1, 0, 0, 0],
                ]
            ],
            [
                [
                    [276, 1, 179, 23, -9387],
                    [0, 0, 78, 0, 0],
                    [0, 0, 1, 0, 1],
                    [0, 0, 1994, 1, 1089],
                    [1, 0, 212, 726, 378],
                ],
                [
                    [276, 9387, -23.1643612, 3.20061556, -178.952978],
                    [-1, 378, 726.194368, -4.95964599, 211.275039],
                    [0, 1089.00046, 2.83103611, -46.795883, 1993.44913],
                    [0, 0, 0.0716450466, -1.83048534, 77.9765052],
                    [0, 0, 0, -0.0234619027, 0.999449236],
                ],
                [
                    [1, 0, 0, 0, 0],
                    [0, 0, 0, -0.99972458, -0.0234683663],
                    [0, 0, -0.000918273258, 0.0234683564, -0.999724158],
                    [0, 0, -0.999999578, -0.0000215503732, 0.000918020348],
                    [0, -1, 0, 0, 0],
                ]
            ],
            [
                [
                    [1, 0, 3, 5, 1],
                    [0, 1, 5, 1, 0],
                    [0, 4, 0, 0, 2],
                    [2, 3, 1, 2, 0],
                    [1, 0, 0, 1, 1],
                ],
                [
                    [1, -4.91934955, -1.61807967, -1.47709789, 2.44948974],
                    [-2.23606798, 2.2, 2.23118395, 1.55235891, 0.9859006],
                    [0, 1.32664992, 4.52727273, 0.18921325, -0.23120239],
                    [0, 0, 2.48964799, 1.53272727, -0.47638792],
                    [0, 0, 0, 0.72965745, -4.26],
                ],
                [
                    [1, 0, 0, 0, 0],
                    [0, 0, -0.67419986, -0.34465617, -0.65319726],
                    [0, 0, -0.67419986, -0.07385489, 0.73484692],
                    [0, -0.89442719, 0.13483997, -0.41851107, 0.08164966],
                    [0, -0.4472136, -0.26967994, 0.83702214, -0.16329932],
                ]
            ],
            [
                [
                    [2, 3, 4, 1, 3],
                    [6, 1, 3, 1, 2],
                    [6, 3, 1, 2, 5],
                    [4, 2, 4, 7, 8],
                    [2, 1, 2, 4, 2],
                ],
                [
                    [2, -5.42137477, -0.30834369, -0.04540342, 2.34767083],
                    [-9.59166305, 9.13043478, -4.88535255, -1.38953883, -4.71937026],
                    [0, -5.6745377, 5.84608277, 0.25399399, 2.02297082],
                    [0, 0, -0.33315191, -2.5960919, -1.10981511],
                    [0, 0, 0, 0.20804747, -1.38042565],
                ],
                [
                    [1, 0, 0, 0, 0],
                    [0, -0.62554324, -0.41858056, 0.62414807, -0.20958329],
                    [0, -0.62554324, -0.23485245, -0.71236487, 0.21465385],
                    [0, -0.41702883, 0.79881786, -0.02753214, -0.43268807],
                    [0, -0.20851441, 0.36266331, 0.31971466, 0.85016446],
                ]
            ],
            [
                [
                    [2, 3, -4, 1, 3],
                    [6, 1, 3, 1, 2],
                    [6, 3, 1, 2, 5],
                    [4, 2, 4, 7, 8],
                    [2, 1, 2, 4, 2],
                ],
                [
                    [2, -0.41702883, 1.57047591, 5.65351552, 0.63044004],
                    [-9.59166305, 9.13043478, -4.88535255, -1.38953883, -4.71937026],
                    [0, -5.6745377, 5.84608277, 0.25399399, 2.02297082],
                    [0, 0, -0.33315191, -2.5960919, -1.10981511],
                    [0, 0, 0, 0.20804747, -1.38042565],
                ],
                [
                    [1, 0, 0, 0, 0],
                    [0, -0.62554324, -0.41858056, 0.62414807, -0.20958329],
                    [0, -0.62554324, -0.23485245, -0.71236487, 0.21465385],
                    [0, -0.41702883, 0.79881786, -0.02753214, -0.43268807],
                    [0, -0.20851441, 0.36266331, 0.31971466, 0.85016446],
                ]
            ],
            [
                [
                    [2, 3, -4, 1, 3],
                    [6, 1, -3, 1, 2],
                    [6, 3, 1, 2, 5],
                    [4, 2, 4, 7, 8],
                    [2, 1, 2, 4, 2],
                ],
                [
                    [2, -0.41702883, 0.17882086, -5.29902262, 2.5912293],
                    [-9.59166305, 6.78260870, 4.6168869, 4.14368183, -5.15726982],
                    [0, 7.6553847, 5.29216067, -0.79849986, -2.2262643],
                    [0, 0, 2.16696081, 0.722930117, 0.507133854],
                    [0, 0, 0, 0.00734356218, -1.79769949],
                ],
                [
                    [1, 0, 0, 0, 0],
                    [0, -0.62554324, 0.60870146, -0.48771379, 0.01770414],
                    [0, -0.62554324, -0.01776366, 0.77828243, -0.05154189],
                    [0, -0.41702883, -0.72002041, -0.37847324, -0.40548191],
                    [0, -0.20851441, -0.33277259, -0.11475943, 0.91247708],
                ]
            ],
            [
                [
                    [2, 3, -4, 1, 3],
                    [6, 1, -3, 1, 2],
                    [6, 3, -1, 2, 5],
                    [4, 2, 4, 7, 8],
                    [2, 1, 2, 4, 2],
                ],
                [
                    [2, -0.41702883, -0.51483142, -5.14794709, 2.83895691],
                    [-9.59166305, 6, 5.24883889, 4.23952257, -5.38900326],
                    [0, 7.69528371, 5.39500734, -1.61830122, -1.9997171],
                    [0, 0, 1.44069354, -0.53170558, 0.81435389],
                    [0, 0, 0, 0.01205559, -1.86330176],
                ],
                [
                    [1, 0, 0, 0, 0],
                    [0, -0.62554324, 0.54192781, -0.55908743, 0.04930663],
                    [0, -0.62554324, 0.08128917, 0.77091413, -0.08819936],
                    [0, -0.41702883, -0.75869894, -0.3038824, -0.39764099],
                    [0, -0.20851441, -0.35225308, -0.0277153, 0.91196018],
                ]
            ],
            [
                [
                    [2, 3, -4, 1, 3],
                    [6, 1, -3, 1, 2],
                    [6, 3, -1, 2, 5],
                    [4, 2, -4, 7, 8],
                    [2, 1, 2, 4, 2],
                ],
                [
                    [2, -0.41702883, 0.03717395, -1.60317639, 5.67930722],
                    [-9.59166305, 3.91304348, 4.84946126, 3.56184324, -8.54180015],
                    [0, 4.63364861, 3.87424302, 2.1007241, -1.50258152],
                    [0, 0, 3.3084662, 3.23304595, -4.20305002],
                    [0, 0, 0, -1.1066076, -2.02033245],
                ],
                [
                    [1, 0, 0, 0, 0],
                    [0, -0.62554324, 0.61826154, -0.00874193, 0.47578556],
                    [0, -0.62554324, -0.14673929, 0.44532824, -0.62357517],
                    [0, -0.41702883, -0.36782649, -0.82672783, -0.08550867],
                    [0, -0.20851441, -0.67891378, 0.34369673, 0.61438618],
                ]
            ],
            [
                [
                    [2, 3, -4, 1, 3],
                    [6, 1, -3, 1, 2],
                    [6, 3, -1, 2, 5],
                    [4, 2, -4, 7, 8],
                    [2, 1, -2, 4, 2],
                ],
                [
                    [2, -0.41702883, 2.17976729, -5.04516482, 2.14965427],
                    [-9.59166305, 3.39130435, 0.97143158, 9.75962393, -4.87236071],
                    [0, 3.42292947, 2.37378116, 5.01439588, -2.47883664],
                    [0, 0, 2.21729992, 4.91294728, -0.2304446],
                    [0, 0, 0, -0.05261574, -1.6780328],
                ],
                [
                    [1, 0, 0, 0, 0],
                    [0, -0.62554324, 0.74159762, -0.23916734, -0.03908462],
                    [0, -0.62554324, -0.29399049, 0.72258181, 0.01186497],
                    [0, -0.41702883, -0.56149534, -0.58267893, -0.41387824],
                    [0, -0.20851441, -0.21983072, -0.28488555, 0.90941543],
                ]
            ],
            [
                [
                    [2, 3, -4, -1, 3],
                    [6, 1, -3, 1, 2],
                    [6, 3, -1, 2, 5],
                    [4, 2, -4, 7, 8],
                    [2, 1, -2, 4, 2],
                ],
                [
                    [2, 0.41702883, 3.30275797, -3.87980695, 2.97741075],
                    [-9.59166305, 3.39130435, 0.97143158, 9.75962393, -4.87236071],
                    [0, 3.42292947, 2.37378116, 5.01439588, -2.47883664],
                    [0, 0, 2.21729992, 4.91294728, -0.2304446],
                    [0, 0, 0, -0.05261574, -1.6780328],
                ],
                [
                    [1, 0, 0, 0, 0],
                    [0, -0.62554324, 0.74159762, -0.23916734, -0.03908462],
                    [0, -0.62554324, -0.29399049, 0.72258181, 0.01186497],
                    [0, -0.41702883, -0.56149534, -0.58267893, -0.41387824],
                    [0, -0.20851441, -0.21983072, -0.28488555, 0.90941543],
                ]
            ],
            [
                [
                    [2, 3, -4, -1, -3],
                    [6, 1, -3, -1, 2],
                    [6, 3, -1, 2, 5],
                    [4, 2, -4, 7, -8],
                    [2, 1, -2, 4, 2],
                ],
                [
                    [2, 1.66811531, 5.40901082, 1.6335224, -0.53999804],
                    [-9.59166305, 1.47826087, -5.60553228, 3.80737371, -2.60954049],
                    [0, 3.36050676, 1.07881981, 1.72642078, -3.05091629],
                    [0, 0, -6.25579123, 4.44581203, 8.11446752],
                    [0, 0, 0, -1.89955011, 1.99710728],
                ],
                [
                    [1, 0, 0, 0, 0],
                    [0, -0.62554324, 0.64746264, 0.39316321, 0.18684343],
                    [0, -0.62554324, -0.65555592, 0.24737319, -0.34314514],
                    [0, -0.41702883, 0.18344775, -0.86426042, -0.21327869],
                    [0, -0.20851441, -0.34261565, -0.19308836, 0.89546253],
                ]
            ],
            [
                [
                    [2, 1, 2],
                    [1, 1, 1],
                    [2, 2, 5],
                ],
                [
                    [2, -2.23606798, 0],
                    [-2.23606798, 5.4, -0.2],
                    [0, -1.2, 0.6],
                ],
                [
                    [1, 0, 0],
                    [0, -0.4472136, -0.89442719],
                    [0, -0.89442719, 0.4472136],
                ]
            ],
            [
                [
                    [1, 0, 2, -1],
                    [3, 0, 0, 5],
                    [2, 1, 4, -3],
                    [1, 0, 5, 0],
                ],
                [
                    [1, -0.80178373, 0.33553431, -2.0602329],
                    [-3.74165739, 2.92857143, 2.70175631, 1.50560266],
                    [0, 2.21888922, -1.35344189, 5.53493878],
                    [0, 0, -3.81920469, 2.42487047],
                ],
                [
                    [1, 0, 0, 0],
                    [0, -0.80178373, 0.45598252, 0.38629367],
                    [0, -0.53452248, -0.25810331, -0.80477847],
                    [0, -0.26726124, -0.85174093, 0.45067595],
                ]
            ],
            [
                [
                    [1, 0, 2, 0, 0, 4],
                    [18, 1, 5, 0, 0, 9],
                    [3, 5, 3, 6, 0, 4],
                    [2, 0, 8, 0, 0, 7],
                    [7, 0, 4, 0, 6, 0],
                    [0, 0, 1, 0, 0, 0],
                ],
                [
                    [1, -0.30539196, -1.93062477, 0.08035827, -2.04324548, 3.46382941],
                    [-19.6468827, 3.50518135, 7.14425351, 0.23345934, 5.145257, -7.93203589],
                    [0, 5.61467582, 3.5305482, 3.94090969, -1.04189093, -2.994899],
                    [0, 0, 6.85726174, -2.30529555, 2.85098817, -2.79178289],
                    [0, 0, 0, -0.18146142, 0.40821834, 6.60367169],
                    [0, 0, 0, 0, 0.97649143, 4.86134767],
                ],
                [
                    [1, 0, 0, 0, 0, 0],
                    [0, -0.91617588, 0.27280414, 0.15395105, 0.17975794, 0.17374067],
                    [0, -0.15269598, -0.91092065, 0.27785544, 0.20260254, 0.16928104],
                    [0, -0.10179732, -0.15401597, -0.90512946, 0.35757388, 0.13710569],
                    [0, -0.35629062, -0.26709724, -0.25634662, -0.65122832, -0.55848379],
                    [0, 0, -0.02719587, -0.11883815, -0.61211264, 0.78131683],
                ]
            ],
            [
                [
                    [-1, 0, 2, 0, 0, 4],
                    [18, 1, 5, 0, 0, 9],
                    [3, 5, 3, 6, 0, 4],
                    [2, 0, 8, 0, 0, 7],
                    [7, 0, 4, 0, 6, 0],
                    [0, 0, 1, 0, 0, 0],
                ],
                [
                    [-1, -0.30539196, -1.93062477, 0.08035827, -2.04324548, 3.46382941],
                    [-19.6468827, 3.50518135, 7.14425351, 0.23345934, 5.145257, -7.93203589],
                    [0, 5.61467582, 3.5305482, 3.94090969, -1.04189093, -2.994899],
                    [0, 0, 6.85726174, -2.30529555, 2.85098817, -2.79178289],
                    [0, 0, 0, -0.18146142, 0.40821834, 6.60367169],
                    [0, 0, 0, 0, 0.97649143, 4.86134767],
                ],
                [
                    [1, 0, 0, 0, 0, 0],
                    [0, -0.91617588, 0.27280414, 0.15395105, 0.17975794, 0.17374067],
                    [0, -0.15269598, -0.91092065, 0.27785544, 0.20260254, 0.16928104],
                    [0, -0.10179732, -0.15401597, -0.90512946, 0.35757388, 0.13710569],
                    [0, -0.35629062, -0.26709724, -0.25634662, -0.65122832, -0.55848379],
                    [0, 0, -0.02719587, -0.11883815, -0.61211264, 0.78131683],
                ]
            ],
            [
                [
                    [-1, 0, -2, 0, 0, 4],
                    [18, 1, 5, 0, 0, 9],
                    [3, 5, 3, 6, 0, 4],
                    [2, 0, 8, 0, 0, 7],
                    [7, 0, 4, 0, 6, 0],
                    [0, 0, 1, 0, 0, 0],
                ],
                [
                    [-1, 0.30539196, 1.71305783, -1.0310635, -2.85365565, 2.78670524],
                    [-19.6468827, 3.50518135, 7.14425351, 0.23345934, 5.145257, -7.93203589],
                    [0, 5.61467582, 3.5305482, 3.94090969, -1.04189093, -2.994899],
                    [0, 0, 6.85726174, -2.30529555, 2.85098817, -2.79178289],
                    [0, 0, 0, -0.18146142, 0.40821834, 6.60367169],
                    [0, 0, 0, 0, 0.97649143, 4.86134767],
                ],
                [
                    [1, 0, 0, 0, 0, 0],
                    [0, -0.91617588, 0.27280414, 0.15395105, 0.17975794, 0.17374067],
                    [0, -0.15269598, -0.91092065, 0.27785544, 0.20260254, 0.16928104],
                    [0, -0.10179732, -0.15401597, -0.90512946, 0.35757388, 0.13710569],
                    [0, -0.35629062, -0.26709724, -0.25634662, -0.65122832, -0.55848379],
                    [0, 0, -0.02719587, -0.11883815, -0.61211264, 0.78131683],
                ]
            ],
            [
                [
                    [-1, 0, -2, 0, 0, -4],
                    [18, 1, 5, 0, 0, 9],
                    [3, 5, 3, 6, 0, 4],
                    [2, 0, 8, 0, 0, 7],
                    [7, 0, 4, 0, 6, 0],
                    [0, 0, 1, 0, 0, 0],
                ],
                [
                    [-1, 0.30539196, 1.93062477, -0.08035827, 2.04324548, -3.46382941],
                    [-19.6468827, 3.50518135, 7.14425351, 0.23345934, 5.145257, -7.93203589],
                    [0, 5.61467582, 3.5305482, 3.94090969, -1.04189093, -2.994899],
                    [0, 0, 6.85726174, -2.30529555, 2.85098817, -2.79178289],
                    [0, 0, 0, -0.18146142, 0.40821834, 6.60367169],
                    [0, 0, 0, 0, 0.97649143, 4.86134767],
                ],
                [
                    [1, 0, 0, 0, 0, 0],
                    [0, -0.91617588, 0.27280414, 0.15395105, 0.17975794, 0.17374067],
                    [0, -0.15269598, -0.91092065, 0.27785544, 0.20260254, 0.16928104],
                    [0, -0.10179732, -0.15401597, -0.90512946, 0.35757388, 0.13710569],
                    [0, -0.35629062, -0.26709724, -0.25634662, -0.65122832, -0.55848379],
                    [0, 0, -0.02719587, -0.11883815, -0.61211264, 0.78131683],
                ]
            ],
            [
                [
                    [1, 1, 1, 1, 1, 1],
                    [1, 3, 1, 3, 1, 3],
                    [1, 1, 4, 1, 1, 4],
                    [1, 3, 1, 7, 1, 3],
                    [1, 1, 1, 1, 6, 1],
                    [1, 3, 4, 3, 1, 12],
                ],
                [
                    [1, -2.23606798, 0, 0, 0, 0],
                    [-2.23606798, 14, -4.81663783, 0, 0, 0],
                    [0, -4.81663783, 6.68965517, 2.5556354, 0, 0],
                    [0, 0, 2.5556354, 3.79752805, -0.93639647, 0],
                    [0, 0, 0, -0.93639647, 3.45984125, 1.89920523],
                    [0, 0, 0, 0, 1.89920523, 4.05297553],
                ],
                [
                    [1, 0, 0, 0, 0, 0],
                    [0, -0.4472136, -0.27854301, 0.39487562, 0.71918631, -0.22194164],
                    [0, -0.4472136, -0.27854301, 0.54019787, -0.60194389, 0.26127307],
                    [0, -0.4472136, 0.09284767, -0.43195785, 0.2247881, 0.74448777],
                    [0, -0.4472136, -0.37139068, -0.59732454, -0.24655491, -0.49445225],
                    [0, -0.4472136, 0.83562902, 0.0942089, -0.09547561, -0.28936694],
                ]
            ],
            [
                [
                    [-1, 1, 1, 1, 1, 1],
                    [1, 3, 1, 3, 1, 3],
                    [1, 1, 4, 1, 1, 4],
                    [1, 3, 1, 7, 1, 3],
                    [1, 1, 1, 1, 6, 1],
                    [1, 3, 4, 3, 1, 12],
                ],
                [
                    [-1, -2.23606798, 0, 0, 0, 0],
                    [-2.23606798, 14, -4.81663783, 0, 0, 0],
                    [0, -4.81663783, 6.68965517, 2.5556354, 0, 0],
                    [0, 0, 2.5556354, 3.79752805, -0.93639647, 0],
                    [0, 0, 0, -0.93639647, 3.45984125, 1.89920523],
                    [0, 0, 0, 0, 1.89920523, 4.05297553],
                ],
                [
                    [1, 0, 0, 0, 0, 0],
                    [0, -0.4472136, -0.27854301, 0.39487562, 0.71918631, -0.22194164],
                    [0, -0.4472136, -0.27854301, 0.54019787, -0.60194389, 0.26127307],
                    [0, -0.4472136, 0.09284767, -0.43195785, 0.2247881, 0.74448777],
                    [0, -0.4472136, -0.37139068, -0.59732454, -0.24655491, -0.49445225],
                    [0, -0.4472136, 0.83562902, 0.0942089, -0.09547561, -0.28936694],
                ]
            ],
            [
                [
                    [-1, 1, 1, 1, 1, 1],
                    [1, 3, 1, 3, 1, 3],
                    [1, 1, 4, 1, 1, 4],
                    [1, -3, 1, 7, 1, 3],
                    [1, 1, 1, 1, 6, 1],
                    [1, 3, 4, 3, 1, 12],
                ],
                [
                    [-1, -2.23606798, 0, 0, 0, 0],
                    [-2.23606798, 12.8, -4.68794918, 1.06958011, 0.50430647, -3.57558469],
                    [0, -5.15363949, 7.03433735, -1.63261693, -0.20729292, -2.07603724],
                    [0, 0, -2.1048485, 4.43173, 0.61270706, -1.1423561],
                    [0, 0, 0, 1.60019982, 3.60323129, -3.18681111],
                    [0, 0, 0, 0, 0.65297756, 4.13070136],
                ],
                [
                    [1, 0, 0, 0, 0, 0],
                    [0, -0.4472136, -0.15619728, 0.09474724, -0.3682179, -0.79438086],
                    [0, -0.4472136, -0.15619728, -0.56488231, 0.66894781, -0.09496957],
                    [0, -0.4472136, -0.32974981, -0.30386173, -0.55616183, 0.53816088],
                    [0, -0.4472136, -0.24297355, 0.76120654, 0.32134667, 0.24138098],
                    [0, -0.4472136, 0.88511792, 0.01279026, -0.06591475, 0.10980856],
                ]
            ],
            [
                [
                    [1, 0, 0, 0, 0, 0],
                    [0, 2, 0, 0, 0, 0],
                    [0, 0, 3, 0, 0, 0],
                    [0, 0, 0, 4, 0, 0],
                    [0, 0, 0, 0, 5, 0],
                    [0, 0, 0, 0, 0, 6],
                ],
                [
                    [1, 0, 0, 0, 0, 0],
                    [0, 2, 0, 0, 0, 0],
                    [0, 0, 3, 0, 0, 0],
                    [0, 0, 0, 4, 0, 0],
                    [0, 0, 0, 0, 5, 0],
                    [0, 0, 0, 0, 0, 6],
                ],
                [
                    [1, 0, 0, 0, 0, 0],
                    [0, 1, 0, 0, 0, 0],
                    [0, 0, 1, 0, 0, 0],
                    [0, 0, 0, 1, 0, 0],
                    [0, 0, 0, 0, 1, 0],
                    [0, 0, 0, 0, 0, 1],
                ]
            ],
            [
                [
                    [-1, 0, 0, 0, 0, 0],
                    [0, 2, 0, 0, 0, 0],
                    [0, 0, 3, 0, 0, 0],
                    [0, 0, 0, 4, 0, 0],
                    [0, 0, 0, 0, 5, 0],
                    [0, 0, 0, 0, 0, 6],
                ],
                [
                    [-1, 0, 0, 0, 0, 0],
                    [0, 2, 0, 0, 0, 0],
                    [0, 0, 3, 0, 0, 0],
                    [0, 0, 0, 4, 0, 0],
                    [0, 0, 0, 0, 5, 0],
                    [0, 0, 0, 0, 0, 6],
                ],
                [
                    [1, 0, 0, 0, 0, 0],
                    [0, 1, 0, 0, 0, 0],
                    [0, 0, 1, 0, 0, 0],
                    [0, 0, 0, 1, 0, 0],
                    [0, 0, 0, 0, 1, 0],
                    [0, 0, 0, 0, 0, 1],
                ]
            ],
            [
                [
                    [1, 0, 0, 0, 0, 0],
                    [1, 2, 0, 0, 0, 0],
                    [1, 0, 3, 0, 0, 0],
                    [1, 2, 0, 4, 0, 0],
                    [1, 0, 0, 0, 5, 0],
                    [1, 2, 3, 0, 0, 6],
                ],
                [
                    [1, 0, 0, 0, 0, 0],
                    [-2.23606798, 5.4, 0.05100614, -0.7454405, -0.25955661, -0.11977981],
                    [0, -3.13687743, 3.01463415, 1.96993502, 1.65339354, -0.33602279],
                    [0, 0, 1.08894541, 3.48001468, 1.18293912, 1.44640884],
                    [0, 0, 0, 0.48962971, 4.24308431, -0.92617428],
                    [0, 0, 0, 0, -0.85939622, 3.86226686],
                ],
                [
                    [1, 0, 0, 0, 0, 0],
                    [0, -0.4472136, -0.48472606, 0.47259508, -0.15918143, -0.56245516],
                    [0, -0.4472136, -0.34215957, 0.02554568, 0.67070826, 0.48210443],
                    [0, -0.4472136, 0.08553989, -0.79191609, 0.06438799, -0.40175369],
                    [0, -0.4472136, -0.05702659, -0.08302346, -0.7091622, 0.53567158],
                    [0, -0.4472136, 0.79837233, 0.37679878, 0.13324737, -0.05356716],
                ]
            ],
            [
                [
                    [0, 1, 4, 3, 2, 3, 3, 4, 4],
                    [1, 0, 3, 2, 1, 2, 2, 3, 3],
                    [4, 3, 0, 1, 2, 3, 3, 4, 4],
                    [3, 2, 1, 0, 1, 2, 2, 3, 3],
                    [2, 1, 2, 1, 0, 1, 1, 2, 2],
                    [3, 2, 3, 2, 1, 0, 2, 3, 3],
                    [3, 2, 3, 2, 1, 2, 0, 1, 2],
                    [4, 3, 4, 3, 2, 3, 1, 0, 2],
                    [4, 3, 4, 3, 2, 3, 2, 2, 0],
                ],
                [
                    [0, -8.94427191, 0, 0, 0, 0, 0, 0, 0],
                    [-8.94427191, 15, -4.82312140, 0, 0, 0, 0, 0, 0],
                    [0, -4.82312140, -1.70983342, 1.26537775, 0, 0, 0, 0, 0],
                    [0, 0, 1.26537775, -4.01220180, 1.72852393, 0, 0, 0, 0],
                    [0, 0, 0, 1.72852393, -3.79304160, -1.02434534, 0, 0, 0],
                    [0, 0, 0, 0, -1.02434534, -1.58042015, 0.53688980, 0, 0],
                    [0, 0, 0, 0, 0, 0.53688980, -0.93709937, 0.43143348, 0],
                    [0, 0, 0, 0, 0, 0, 0.43143348, -2.21158329, 0.03875743],
                    [0, 0, 0, 0, 0, 0, 0, 0.03875743, -0.75582037],
                ],
                [
                    [1, 0, 0, 0, 0, 0, 0, 0, 0],
                    [0, -0.11180340, 0.95040928, 0.25355008, 0.01863843, 0.05020529, -0.06650501, -0.11135140, 0.01563769],
                    [0, -0.44721360, 0, -0.16578880, 0.72667026, 0.20340694, 0.26196583, 0.07809153, -0.35828151],
                    [0, -0.33541020, -0.02318071, -0.37549485, 0.19090761, 0.10598289, -0.53914186, -0.23074888, 0.59528917],
                    [0, -0.22360680, 0.09272286, -0.43390258, -0.52995197, 0.57651951, 0.37328479, -0.02378336, 0.00009631],
                    [0, -0.33541020, 0.16226500, -0.41801982, -0.18618020, -0.72451029, 0.14815736, 0.32387705, 0.00207989],
                    [0, -0.33541020, -0.11590357, 0.03047094, -0.26531262, -0.14855346, -0.32101321, -0.58421321, -0.57993484],
                    [0, -0.44721360, -0.18544571, 0.49958913, -0.05622105, -0.14191855, 0.47922058, -0.29711522, 0.41807786],
                    [0, -0.44721360, -0.11590357, 0.39204624, -0.21469392, 0.21301118, -0.37720427, 0.62706700, -0.07682959],
                ]
            ],
            [
                [
                    [2, 1, 4, 3, 2, 3, 3, 4, 4],
                    [1, 2, 3, 2, 1, 2, 2, 3, 3],
                    [4, 3, 2, 1, 2, 3, 3, 4, 4],
                    [3, 2, 1, 2, 1, 2, 2, 3, 3],
                    [2, 1, 2, 1, 2, 1, 1, 2, 2],
                    [3, 2, 3, 2, 1, 2, 2, 3, 3],
                    [3, 2, 3, 2, 1, 2, 2, 1, 2],
                    [4, 3, 4, 3, 2, 3, 1, 2, 2],
                    [4, 3, 4, 3, 2, 3, 2, 2, 2],
                ],
                [
                    [2, -8.94427191, 0, 0, 0, 0, 0, 0, 0],
                    [-8.94427191, 17, -4.82312140, 0, 0, 0, 0, 0, 0],
                    [0, -4.82312140, 0.29016658, 1.26537775, 0, 0, 0, 0, 0],
                    [0, 0, 1.26537775, -2.01220180, 1.72852393, 0, 0, 0, 0],
                    [0, 0, 0, 1.72852393, -1.79304160, -1.02434534, 0, 0, 0],
                    [0, 0, 0, 0, -1.02434534, 0.41957985, 0.53688980, 0, 0],
                    [0, 0, 0, 0, 0, 0.53688980, 1.06290063, 0.43143348, 0],
                    [0, 0, 0, 0, 0, 0, 0.43143348, -0.21158329, 0.03875743],
                    [0, 0, 0, 0, 0, 0, 0, 0.03875743, 1.24417963],
                ],
                [
                    [1, 0, 0, 0, 0, 0, 0, 0, 0],
                    [0, -0.11180340, 0.95040928, 0.25355008, 0.01863843, 0.05020529, -0.06650501, -0.11135140, 0.01563769],
                    [0, -0.44721360, 0, -0.16578880, 0.72667026, 0.20340694, 0.26196583, 0.07809153, -0.35828151],
                    [0, -0.33541020, -0.02318071, -0.37549485, 0.19090761, 0.10598289, -0.53914186, -0.23074888, 0.59528917],
                    [0, -0.22360680, 0.09272286, -0.43390258, -0.52995197, 0.57651951, 0.37328479, -0.02378336, 0.00009631],
                    [0, -0.33541020, 0.16226500, -0.41801982, -0.18618020, -0.72451029, 0.14815736, 0.32387705, 0.00207989],
                    [0, -0.33541020, -0.11590357, 0.03047094, -0.26531262, -0.14855346, -0.32101321, -0.58421321, -0.57993484],
                    [0, -0.44721360, -0.18544571, 0.49958913, -0.05622105, -0.14191855, 0.47922058, -0.29711522, 0.41807786],
                    [0, -0.44721360, -0.11590357, 0.39204624, -0.21469392, 0.21301118, -0.37720427, 0.62706700, -0.07682959],
                ]
            ],
            [
                [
                    [2, -1, 4, 3, 2, 3, 3, 4, 4],
                    [1, 2, 3, 2, 1, 2, 2, 3, 3],
                    [4, 3, 2, 1, 2, 3, 3, 4, 4],
                    [3, 2, 1, 2, 1, 2, 2, 3, 3],
                    [2, 1, 2, 1, 2, 1, 1, 2, 2],
                    [3, 2, 3, 2, 1, 2, 2, 3, 3],
                    [3, 2, 3, 2, 1, 2, 2, 1, 2],
                    [4, 3, 4, 3, 2, 3, 1, 2, 2],
                    [4, 3, 4, 3, 2, 3, 2, 2, 2],
                ],
                [
                    [2, -8.72066511, -1.90081857, -0.50710015, -0.03727687, -0.10041059, 0.13301002, 0.22270281, -0.03127538],
                    [-8.94427191, 17, -4.82312140, 0, 0, 0, 0, 0, 0],
                    [0, -4.82312140, 0.29016658, 1.26537775, 0, 0, 0, 0, 0],
                    [0, 0, 1.26537775, -2.01220180, 1.72852393, 0, 0, 0, 0],
                    [0, 0, 0, 1.72852393, -1.79304160, -1.02434534, 0, 0, 0],
                    [0, 0, 0, 0, -1.02434534, 0.41957985, 0.53688980, 0, 0],
                    [0, 0, 0, 0, 0, 0.53688980, 1.06290063, 0.43143348, 0],
                    [0, 0, 0, 0, 0, 0, 0.43143348, -0.21158329, 0.03875743],
                    [0, 0, 0, 0, 0, 0, 0, 0.03875743, 1.24417963],
                ],
                [
                    [1, 0, 0, 0, 0, 0, 0, 0, 0],
                    [0, -0.11180340, 0.95040928, 0.25355008, 0.01863843, 0.05020529, -0.06650501, -0.11135140, 0.01563769],
                    [0, -0.44721360, 0, -0.16578880, 0.72667026, 0.20340694, 0.26196583, 0.07809153, -0.35828151],
                    [0, -0.33541020, -0.02318071, -0.37549485, 0.19090761, 0.10598289, -0.53914186, -0.23074888, 0.59528917],
                    [0, -0.22360680, 0.09272286, -0.43390258, -0.52995197, 0.57651951, 0.37328479, -0.02378336, 0.00009631],
                    [0, -0.33541020, 0.16226500, -0.41801982, -0.18618020, -0.72451029, 0.14815736, 0.32387705, 0.00207989],
                    [0, -0.33541020, -0.11590357, 0.03047094, -0.26531262, -0.14855346, -0.32101321, -0.58421321, -0.57993484],
                    [0, -0.44721360, -0.18544571, 0.49958913, -0.05622105, -0.14191855, 0.47922058, -0.29711522, 0.41807786],
                    [0, -0.44721360, -0.11590357, 0.39204624, -0.21469392, 0.21301118, -0.37720427, 0.62706700, -0.07682959],
                ]
            ],
            [
                [
                    [2, 1, 4, 3, 2, 3, 3, 4, 4],
                    [-1, 2, 3, 2, 1, 2, 2, 3, 3],
                    [4, 3, 2, 1, 2, 3, 3, 4, 4],
                    [3, 2, 1, 2, 1, 2, 2, 3, 3],
                    [2, 1, 2, 1, 2, 1, 1, 2, 2],
                    [3, 2, 3, 2, 1, 2, 2, 3, 3],
                    [3, 2, 3, 2, 1, 2, 2, 1, 2],
                    [4, 3, 4, 3, 2, 3, 1, 2, 2],
                    [4, 3, 4, 3, 2, 3, 2, 2, 2],
                ],
                [
                    [2, 8.72066511, -1.95140102, 0.34851618, -0.00198, 0.04106284, -0.08130576, -0.10874822, 0.02106302],
                    [8.94427191, 14.2, -7.81488963, 0, 0, 0, 0, 0, 0],
                    [0, -7.81488963, 3.31455238, -1.24955294, 0, 0, 0, 0, 0],
                    [0, 0, -1.24955294, -1.76971765, 1.71711969, 0, 0, 0, 0],
                    [0, 0, 0, 1.71711969, -2.01838247, -1.32960223, 0, 0, 0],
                    [0, 0, 0, 0, -1.32960223, 0.35144073, 0.54277193, 0, 0],
                    [0, 0, 0, 0, 0, 0.54277193, 0.95904903, 0.32024537, 0],
                    [0, 0, 0, 0, 0, 0, 0.32024537, -0.27466645, 0.10611045],
                    [0, 0, 0, 0, 0, 0, 0, 0.10611045, 1.23772444],
                ],
                [
                    [1, 0, 0, 0, 0, 0, 0, 0, 0],
                    [0, -0.11180340, -0.97570051, 0.17425809, -0.00099, 0.02053142, -0.04065288, -0.05437411, 0.01053151],
                    [0, 0.44721360, -0.07439359, -0.06784458, 0.69010472, 0.32963469, 0.26891634, 0.03865643, -0.36214478],
                    [0, 0.33541020, -0.04864196, -0.28264768, 0.28175307, 0.03930689, -0.57482207, -0.16594177, 0.60527460],
                    [0, 0.22360680, -0.10872909, -0.50989974, -0.54560516, 0.57542642, 0.21002248, -0.06746467, 0.02680978],
                    [0, 0.33541020, -0.16309363, -0.46716879, -0.07072838, -0.70197639, 0.25633071, 0.28079118, -0.01820230],
                    [0, 0.33541020, 0.00858388, 0.05004737, -0.22639052, -0.20820425, -0.36770615, -0.59016870, -0.55390703],
                    [0, 0.44721360, 0.04005809, 0.50595144, -0.13976200, -0.08273095, 0.47883981, -0.32050653, 0.42897397],
                    [0, 0.44721360, -0.00286129, 0.38523435, -0.26626327, 0.12367122, -0.34828248, 0.65847838, -0.10247515],
                ]
            ],
            [
                [
                    [2, -1, 4, 3, 2, 3, 3, 4, 4],
                    [-1, 2, 3, 2, 1, 2, 2, 3, 3],
                    [4, 3, 2, 1, 2, 3, 3, 4, 4],
                    [3, 2, 1, 2, 1, 2, 2, 3, 3],
                    [2, 1, 2, 1, 2, 1, 1, 2, 2],
                    [3, 2, 3, 2, 1, 2, 2, 3, 3],
                    [3, 2, 3, 2, 1, 2, 2, 1, 2],
                    [4, 3, 4, 3, 2, 3, 1, 2, 2],
                    [4, 3, 4, 3, 2, 3, 2, 2, 2],
                ],
                [
                    [2, 8.94427191, 0, 0, 0, 0, 0, 0, 0],
                    [8.94427191, 14.2, -7.81488963, 0, 0, 0, 0, 0, 0],
                    [0, -7.81488963, 3.31455238, -1.24955294, 0, 0, 0, 0, 0],
                    [0, 0, -1.24955294, -1.76971765, 1.71711969, 0, 0, 0, 0],
                    [0, 0, 0, 1.71711969, -2.01838247, -1.32960223, 0, 0, 0],
                    [0, 0, 0, 0, -1.32960223, 0.35144073, 0.54277193, 0, 0],
                    [0, 0, 0, 0, 0, 0.54277193, 0.95904903, 0.32024537, 0],
                    [0, 0, 0, 0, 0, 0, 0.32024537, -0.27466645, 0.10611045],
                    [0, 0, 0, 0, 0, 0, 0, 0.10611045, 1.23772444],
                ],
                [
                    [1, 0, 0, 0, 0, 0, 0, 0, 0],
                    [0, -0.11180340, -0.97570051, 0.17425809, -0.00099, 0.02053142, -0.04065288, -0.05437411, 0.01053151],
                    [0, 0.44721360, -0.07439359, -0.06784458, 0.69010472, 0.32963469, 0.26891634, 0.03865643, -0.36214478],
                    [0, 0.33541020, -0.04864196, -0.28264768, 0.28175307, 0.03930689, -0.57482207, -0.16594177, 0.60527460],
                    [0, 0.22360680, -0.10872909, -0.50989974, -0.54560516, 0.57542642, 0.21002248, -0.06746467, 0.02680978],
                    [0, 0.33541020, -0.16309363, -0.46716879, -0.07072838, -0.70197639, 0.25633071, 0.28079118, -0.01820230],
                    [0, 0.33541020, 0.00858388, 0.05004737, -0.22639052, -0.20820425, -0.36770615, -0.59016870, -0.55390703],
                    [0, 0.44721360, 0.04005809, 0.50595144, -0.13976200, -0.08273095, 0.47883981, -0.32050653, 0.42897397],
                    [0, 0.44721360, -0.00286129, 0.38523435, -0.26626327, 0.12367122, -0.34828248, 0.65847838, -0.10247515],
                ]
            ],
            [
                [
                    [2, -1, 4, 3, 2, 3, 3, 4, 4],
                    [-1, 2, 3, 2, 1, 2, 2, 3, 3],
                    [4, 3, 2, 1, 2, 3, 3, 4, 4],
                    [2, 1, 2, 1, 2, 1, 1, 2, 2],
                    [3, 2, 1, 2, 1, 2, 2, 3, 3],
                    [3, 2, 3, 2, 1, 2, 2, 3, 3],
                    [3, 2, 3, 2, 1, 2, 2, 1, 2],
                    [4, 3, 4, 3, 2, 3, 1, 2, 2],
                    [4, 3, 4, 3, 2, 3, 2, 2, 2],
                ],
                [
                    [2, 8.83246851, -0.08806614, -0.31770539, 0.81699989, 1.06699795, -0.26203636, 0.06068528, -0.02210057],
                    [8.94427191, 14.075, -7.90856085, -0.19873204, 0.97821858, 1.01494456, -0.17269148, 0.06660000, -0.02763858],
                    [0, -7.71244935, 3.35287194, -1.04908079, -0.66254817, -1.07213482, 0.32360439, -0.05398652, 0.01699548],
                    [0, 0, -1.44982100, -2.46274968, -0.70573107, 0.98750738, -0.02495447, 0.08138456, -0.03925494],
                    [0, 0, 0, -2.03325121, -1.34962169, 0.71558897, -1.03073712, 0.04428555, 0.00860020],
                    [0, 0, 0, 0, -1.20338334, -0.49873912, 0.26784878, -0.08470110, 0.06314171],
                    [0, 0, 0, 0, 0, 0.99851458, 0.05150182, 0.38179228, -0.03064069],
                    [0, 0, 0, 0, 0, 0, 0.31943468, 1.01452210, -0.49648771],
                    [0, 0, 0, 0, 0, 0, 0, -0.49832448, -0.18278536],
                ],
                [
                    [1, 0, 0, 0, 0, 0, 0, 0, 0],
                    [0, -0.11180340, -0.97235167, 0.19123213, -0.01388343, -0.03526191, -0.03832158, 0.00731205, -0.05004345],
                    [0, 0.44721360, -0.09712644, -0.23163984, -0.69623358, 0.46902986, -0.10208602, 0.14320411, -0.03535903],
                    [0, 0.22360680, -0.12829388, -0.54430186, 0.55670254, 0.24634099, -0.49601009, -0.13300935, -0.05437895],
                    [0, 0.33541020, -0.04022774, -0.22659647, -0.26029735, -0.82065696, -0.23397373, -0.19369463, -0.03227838],
                    [0, 0.33541020, -0.15619962, -0.36081024, 0.18995615, -0.02593842, 0.78796438, -0.10414682, 0.25382490],
                    [0, 0.33541020, 0.01775819, 0.11047828, 0.22792126, -0.11496774, 0.14792463, 0.56420089, -0.68528036],
                    [0, 0.44721360, 0.04783840, 0.51105893, 0.09573409, 0.16846802, 0.02384125, -0.66521584, -0.23643868],
                    [0, 0.44721360, 0.00434895, 0.39823620, 0.20049232, -0.04831151, -0.20976705, 0.39057483, 0.63427670],
                ]
            ],
            [
                [
                    [1, 2],
                    [3, 4],
                ],
                [
                    [1, 2],
                    [3, 4],
                ],
                [
                    [1, 0],
                    [0, 1],
                ]
            ],
            [
                [
                    [4, 1, 2],
                    [1, 3, 1],
                    [2, 1, 2],
                ],
                [
                    [4, -2.23606798, 0],
                    [-2.23606798, 3, 1],
                    [0, 1, 2],
                ],
                [
                    [1, 0, 0],
                    [0, -0.4472136, -0.89442719],
                    [0, -0.89442719, 0.4472136],
                ]
            ],
            [
                [
                    [1, 2, 3],
                    [4, 5, 6],
                    [7, 8, 9],
                ],
                [
                    [1, -3.5970073, -0.24806947],
                    [-8.06225775, 14.04615385, 2.83076923],
                    [0, 0.83076923, -0.04615385],
                ],
                [
                    [1, 0, 0],
                    [0, -0.49613894, -0.86824314],
                    [0, -0.86824314, 0.49613894],
                ]
            ],
            [
                [
                    [1, 1, 1, 1],
                    [1, 2, 3, 4],
                    [1, 3, 6, 10],
                    [1, 4, 10, 20],
                ],
                [
                    [1, -1.73205081, 0, 0],
                    [-1.73205081, 20.6666667, 10.2740233, 0],
                    [0, 10.2740233, 7.17543860, -0.36464228],
                    [0, 0, -0.36464228, 0.15789474],
                ],
                [
                    [1, 0, 0, 0],
                    [0, -0.57735027, 0.65561007, 0.48666426],
                    [0, -0.57735027, 0.09365858, -0.81110711],
                    [0, -0.57735027, -0.74926865, 0.32444284],
                ]
            ],
            [
                [
                    [1, 0, 0],
                    [0, 1, 0],
                    [0, 0, 1],
                ],
                [
                    [1, 0, 0],
                    [0, 1, 0],
                    [0, 0, 1],
                ],
                [
                    [1, 0, 0],
                    [0, 1, 0],
                    [0, 0, 1],
                ]
            ],
            [
                [
                    [1, 2, 3],
                    [0, 4, 5],
                    [0, 0, 6],
                ],
                [
                    [1, 2, 3],
                    [0, 4, 5],
                    [0, 0, 6],
                ],
                [
                    [1, 0, 0],
                    [0, 1, 0],
                    [0, 0, 1],
                ]
            ],
            // Additional reasonable test cases for numerical precision
            // Moderate scale differences
            [
                [
                    [10.0, 0.1, 0.01, 0.001],
                    [0.1, 10.0, 0.1, 0.01],
                    [0.01, 0.1, 10.0, 0.1],
                    [0.001, 0.01, 0.1, 10.0],
                ],
                [
                    [10.0, -0.1005037313, -0.0, 0.0],
                    [-0.1005037313, 10.0201960202, 0.1009361742, 0.0],
                    [0.0, 0.1009361742, 10.0182746205, -0.0938135019],
                    [0.0, 0.0, -0.0938135019, 9.9615293593],
                ],
                [
                    [1.0, 0.0, 0.0, 0.0],
                    [0.0, -0.99498793, 0.09952248, 0.00971011],
                    [0.0, -0.09949879, -0.97570868, -0.19517314],
                    [0.0, -0.00994988, -0.19516106, 0.98072074],
                ]
            ],
            // Near-singular well-defined
            [
                [
                    [1000.0, 1000.1, 1000.2],
                    [1000.1, 1000.0, 1000.3],
                    [1000.2, 1000.3, 1000.0],
                ],
                [
                    [1000.0, -1414.42570, -0.0],
                    [-1414.42570, 2000.3, 0.100014998],
                    [0.0, 0.100014998, -0.299995000],
                ],
                [
                    [1.0, 0.0, 0.0],
                    [0.0, -0.70707143, -0.70714213],
                    [0.0, -0.70714213, 0.70707143],
                ]
            ],
            [
                [
                    [5.0, -2.0, 1.0],
                    [3.0, 4.0, -1.0],
                    [1.0, 1.0, 3.0],
                ],
                [
                    [5.0, 1.58113883, 1.58113883],
                    [-3.16227766, 3.9, 1.3],
                    [0.0, -0.7, 3.1],
                ],
                [
                    [1.0, 0.0, 0.0],
                    [0.0, -0.9486833, -0.31622777],
                    [0.0, -0.31622777, 0.9486833],
                ]
            ],
            [
                [
                    [2, 1],
                    [3, 4]
                ],
                [
                    [2, 1],
                    [3, 4]
                ],
                [
                    [1.0, 0.0],
                    [0.0, 1.0]
                ]
            ],
            [
                [
                    [-1, 2],
                    [3, -4]
                ],
                [
                    [-1, 2],
                    [3, -4]
                ],
                [
                    [1.0, 0.0],
                    [0.0, 1.0]
                ]
            ],
            [
                [
                    [0, 1],
                    [1, 0]
                ],
                [
                    [0, 1],
                    [1, 0]
                ],
                [
                    [1.0, 0.0],
                    [0.0, 1.0]
                ]
            ],
            [
                [
                    [5, -2],
                    [-3, 1]
                ],
                [
                    [5, -2],
                    [-3, 1]
                ],
                [
                    [1.0, 0.0],
                    [0.0, 1.0]
                ]
            ],
            [
                [
                    [10, 5],
                    [2, 8]
                ],
                [
                    [10, 5],
                    [2, 8]
                ],
                [
                    [1.0, 0.0],
                    [0.0, 1.0]
                ]
            ],
            [
                [
                    [1, 2, 3],
                    [4, 5, 6],
                    [7, 8, 9]
                ],
                [
                    [1.0, -3.5970073, -0.24806947],
                    [-8.06225775, 14.0461538, 2.83076923],
                    [0.0, 0.83076923, -0.04615385]
                ],
                [
                    [1.0, 0.0, 0.0],
                    [0.0, -0.49613894, -0.86824314],
                    [0.0, -0.86824314, 0.49613894]
                ]
            ],
            [
                [
                    [-1, 2, -3],
                    [4, -5, 6],
                    [-7, 8, -9]
                ],
                [
                    [-1.0, -3.5970073, 0.24806947],
                    [-8.06225775, -14.0461538, 2.83076923],
                    [0.0, 0.83076923, 0.04615385]
                ],
                [
                    [1.0, 0.0, 0.0],
                    [0.0, -0.49613894, 0.86824314],
                    [0.0, 0.86824314, 0.49613894]
                ]
            ],
            [
                [
                    [10, 1, 1],
                    [1, 10, 1],
                    [1, 1, 10]
                ],
                [
                    [10.0, -1.41421356, -0.0],
                    [-1.41421356, 11.0, -0.0],
                    [0.0, -0.0, 9.0]
                ],
                [
                    [1.0, 0.0, 0.0],
                    [0.0, -0.70710678, -0.70710678],
                    [0.0, -0.70710678, 0.70710678]
                ]
            ],
            [
                [
                    [3, 7, 2],
                    [1, 5, 8],
                    [6, 4, 9]
                ],
                [
                    [3.0, -3.12358076, -6.57595949],
                    [-6.08276253, 10.8378378, 3.02702703],
                    [0.0, 7.02702703, 3.16216216]
                ],
                [
                    [1.0, 0.0, 0.0],
                    [0.0, -0.16439899, -0.98639392],
                    [0.0, -0.98639392, 0.16439899]
                ]
            ],
            [
                [
                    [0, 1, 2],
                    [3, 0, 4],
                    [5, 6, 0]
                ],
                [
                    [0.0, -2.22948161, 0.17149859],
                    [-5.83095189, 4.41176471, 3.35294118],
                    [0.0, 1.35294118, -4.41176471]
                ],
                [
                    [1.0, 0.0, 0.0],
                    [0.0, -0.51449576, -0.85749293],
                    [0.0, -0.85749293, 0.51449576]
                ]
            ],
            [
                [
                    [1.0, 2.0, 3.0, 4.0],
                    [5.0, 6.0, 7.0, 8.0],
                    [9.0, 10.0, 11.0, 12.0],
                    [13.0, 14.0, 15.0, 16.0]
                ],
                [
                    [1.0, -5.36690193, 0.44312937, 0.0],
                    [-16.583124, 33.0872727, -9.55746361, -0.0],
                    [0.0, -2.20899439, -0.08727273, -0.0],
                    [0.0, 0.0, -0.0, -0.0]
                ],
                [
                    [1.0, 0.0, 0.0, 0.0],
                    [0.0, -0.30151134, 0.86164044, 0.40824829],
                    [0.0, -0.54272042, 0.19694639, -0.81649658],
                    [0.0, -0.7839295, -0.46774767, 0.40824829]
                ]
            ],
            [
                [
                    [0.49671415, -0.1382643, 0.64768854, 1.52302986],
                    [-0.23415337, -0.23413696, 1.57921282, 0.76743473],
                    [-0.46947439, 0.54256004, -0.46341769, -0.46572975],
                    [0.24196227, -1.91328024, -1.72491783, -0.56228753]
                ],
                [
                    [0.49671415, 0.16758089, -1.62147505, 0.31776202],
                    [0.57773674, 1.19573961, 0.4114327, -0.84701388],
                    [0.0, -1.75877098, -1.51197599, 0.95104762],
                    [0.0, 0.0, -1.15114643, -0.94360581]
                ],
                [
                    [1.0, 0.0, 0.0, 0.0],
                    [0.0, -0.40529424, 0.21739775, 0.88796103],
                    [0.0, -0.81260954, -0.53065353, -0.24098251],
                    [0.0, 0.4188106, -0.81923443, 0.3917303]
                ]
            ],
            [
                [
                    [5.0, 4.0, -3.0, 1.0],
                    [-2.0, 3.0, -3.0, -1.0],
                    [-3.0, 1.0, -1.0, 3.0],
                    [1.0, -4.0, -2.0, 3.0]
                ],
                [
                    [5.0, 0.53452248, -0.73150185, 5.01788708],
                    [3.74165739, 0.07142857, 1.00466354, -3.96230171],
                    [0.0, -4.69748087, 2.35539224, 1.22359303],
                    [0.0, 0.0, 2.55989924, 2.57317919]
                ],
                [
                    [1.0, 0.0, 0.0, 0.0],
                    [0.0, -0.53452248, -0.12191698, 0.83631451],
                    [0.0, -0.80178373, -0.23977005, -0.54740586],
                    [0.0, 0.26726124, -0.96314411, 0.03041144]
                ]
            ],
            [
                [
                    [-0.60063869, -0.29169375, -0.60170661, 1.85227818, -0.01349722],
                    [-1.05771093, 0.82254491, -1.22084365, 0.2088636, -1.95967012],
                    [-1.32818605, 0.19686124, 0.73846658, 0.17136828, -0.11564828],
                    [-0.3011037, -1.47852199, -0.71984421, -0.46063877, 1.05712223],
                    [0.34361829, -1.76304016, 0.32408397, -0.38508228, -0.676922]
                ],
                [
                    [-0.60063869, 0.31015459, 1.76780159, -0.7570182, 0.2895822],
                    [1.7582854, 0.39700388, -0.07430313, 0.92790473, 0.78679021],
                    [0.0, 1.97183457, -0.38462946, 0.21550643, 0.86761491],
                    [0.0, 0.0, -0.79090478, -1.12527382, 0.96518741],
                    [0.0, 0.0, 0.0, 1.69392189, 1.53635012]
                ],
                [
                    [1.0, 0.0, 0.0, 0.0, 0.0],
                    [0.0, -0.60155816, 0.12550735, 0.13458747, -0.77734284],
                    [0.0, -0.75538706, -0.21721268, 0.20166836, 0.5844133],
                    [0.0, -0.17124848, 0.90607972, -0.31530417, 0.22422486],
                    [0.0, 0.19542805, 0.34071411, 0.91749625, 0.06262911]
                ]
            ],
            [
                [
                    [3.0, -1.0, -1.0, -3.0, -1.0],
                    [-1.0, -3.0, -1.0, 1.0, -2.0],
                    [3.0, -2.0, -3.0, 0.0, 3.0],
                    [-3.0, 0.0, -2.0, -3.0, 3.0],
                    [3.0, 2.0, 1.0, -1.0, 0.0]
                ],
                [
                    [3.0, 0.75592895, -2.03822035, 0.92566765, -2.53325258],
                    [5.29150262, -0.32142857, 0.48712331, -0.1974799, 1.00660488],
                    [0.0, 2.94052439, -2.35167956, 3.23950722, 2.27257513],
                    [0.0, 0.0, -2.21607557, -4.67123296, 1.45382647],
                    [0.0, 0.0, 0.0, 1.47811757, -1.65565891]
                ],
                [
                    [1.0, 0.0, 0.0, 0.0, 0.0],
                    [0.0, -0.18898224, -0.59907152, -0.16294242, 0.76082113],
                    [0.0, 0.56694671, 0.19050933, -0.79220956, 0.12116781],
                    [0.0, -0.56694671, 0.70924559, -0.17710277, 0.3797061],
                    [0.0, 0.56694671, 0.31904575, 0.56079265, 0.51214534]
                ]
            ],
            [
                [
                    [2.75114943, 7.74425485, -0.5557015, -7.60811508, 4.26489574],
                    [5.21570097, 1.22554395, 5.4193436, -0.12408807, 0.45465659],
                    [-1.44917963, -9.49161747, -7.84217146, -9.37141629, 2.72820823],
                    [-3.71288038, 0.17141382, 8.15132948, -5.01415542, -1.79234154],
                    [5.11102277, -5.42403669, -8.4604018, -4.20497094, -6.77557425]
                ],
                [
                    [2.75114943, -10.9675585, -3.60894301, 1.62011285, -0.64688722],
                    [-8.31935651, -2.63185355, 0.70254685, 3.48721613, 3.47258678],
                    [0.0, 3.53544314, -3.70705042, -0.99121143, -6.71329903],
                    [0.0, 0.0, 6.68295687, -2.76882075, -14.5790567],
                    [0.0, 0.0, 0.0, 9.06051665, -9.29863247]
                ],
                [
                    [1.0, 0.0, 0.0, 0.0, 0.0],
                    [0.0, -0.62693563, -0.51168233, -0.45594117, 0.37047343],
                    [0.0, 0.17419372, -0.23065378, 0.61526638, 0.73341848],
                    [0.0, 0.44629418, 0.38195159, -0.61299631, 0.52836542],
                    [0.0, -0.61435314, 0.73422953, 0.19442339, 0.21372123]
                ]
            ],
            [
                [
                    [0.61167629, 0.91540212, 0.32875111, -0.5297602, 0.51326743, 0.09707755],
                    [0.96864499, -0.70205309, -0.32766215, -0.39210815, -1.46351495, 0.29612028],
                    [0.26105527, 0.00511346, -0.23458713, -1.41537074, -0.42064532, -0.34271452],
                    [-0.80227727, -0.16128571, 0.40405086, 1.8861859, 0.17457781, 0.25755039],
                    [-0.07444592, -1.91877122, -0.02651388, 0.06023021, 2.46324211, -0.19236096],
                    [0.30154734, -0.03471177, -1.16867804, 1.14282281, 0.75193303, 0.79103195]
                ],
                [
                    [0.61167629, -1.05072017, 0.39740878, -0.28628542, -0.39227893, -0.04198814],
                    [-1.32156906, 0.60569124, 1.17569676, -1.04107517, -0.77816898, 0.9779702],
                    [0.0, 2.2037329, 1.71910325, 0.54297673, -0.88488497, 0.05262599],
                    [0.0, 0.0, 1.52824811, -0.21571199, 0.20664317, -0.39457646],
                    [0.0, 0.0, 0.0, -0.44470419, 1.88762626, 1.49327523],
                    [0.0, 0.0, 0.0, 0.0, 0.96612464, 0.20711096]
                ],
                [
                    [1.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                    [0.0, -0.73295072, 0.28823504, -0.52985579, 0.29737348, 0.10259465],
                    [0.0, -0.19753434, -0.29154264, -0.09273955, -0.61179346, 0.70220454],
                    [0.0, 0.6070642, 0.34796005, -0.38105128, 0.29882464, 0.52526242],
                    [0.0, 0.05633146, 0.72454153, -0.08792703, -0.63459529, -0.24783863],
                    [0.0, -0.22817373, 0.43114594, 0.74680719, 0.21276849, 0.39882142]
                ]
            ],
            [
                [
                    [0.90906125, 0.14027943, -0.14018511, 0.05868571, 0.21904556, -0.09905363],
                    [-0.05662977, 1.00996514, -0.05034757, -0.15506634, 0.0068563, -0.10623037],
                    [0.04735924, -0.09194242, 1.15499344, -0.07832533, -0.03220615, 0.08135172],
                    [-0.12308643, 0.02274599, 0.13071428, 0.83925168, 0.01846339, 0.02598828],
                    [0.07818229, -0.12369507, -0.13204566, 0.05219416, 1.02969847, 0.02504929],
                    [0.03464482, -0.06800247, 0.02322537, 0.02930725, -0.07143514, 1.18657745]
                ],
                [
                    [0.90906125, -0.04855818, 0.04322123, 0.27543184, -0.00238129, -0.14308192],
                    [0.16707134, 0.88839352, 0.01774044, -0.11785488, -0.1437576, -0.12702033],
                    [0.0, -0.19567277, 1.06244692, 0.12762037, 0.00096085, -0.08895704],
                    [0.0, 0.0, 0.18711939, 1.05967113, 0.05730558, -0.07820998],
                    [0.0, 0.0, 0.0, 0.08164924, 1.1407152, -0.02892825],
                    [0.0, 0.0, 0.0, 0.0, 0.04146611, 1.06925941]
                ],
                [
                    [1.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                    [0.0, -0.33895564, -0.20412995, 0.75374831, -0.02110506, 0.52426911],
                    [0.0, 0.28346719, -0.84958045, -0.22464757, 0.33422446, 0.18890974],
                    [0.0, -0.73672978, -0.40668272, -0.1080699, -0.20596809, -0.48758223],
                    [0.0, 0.46795751, -0.19094433, 0.58514757, -0.13926823, -0.6186782],
                    [0.0, 0.20736544, -0.18626179, -0.16528817, -0.90886198, 0.26259447]
                ]
            ],
            [
                [
                    [-1.0856306, 0.99734545, 0.2829785, -1.50629471, -0.57860025, 1.65143654, -2.42667924],
                    [-0.42891263, 1.26593626, -0.8667404, -0.67888615, -0.09470897, 1.49138963, -0.638902],
                    [-0.44398196, -0.43435128, 2.20593008, 2.18678609, 1.0040539, 0.3861864, 0.73736858],
                    [1.49073203, -0.93583387, 1.17582904, -1.25388067, -0.6377515, 0.9071052, -1.4286807],
                    [-0.14006872, -0.8617549, -0.25561937, -2.79858911, -1.7715331, -0.69987723, 0.92746243],
                    [-0.17363568, 0.00284592, 0.68822271, -0.87953634, 0.28362732, -0.80536652, -1.72766949],
                    [-0.39089979, 0.57380586, 0.33858905, -0.01183049, 2.39236527, 0.41291216, 0.97873601]
                ],
                [
                    [-1.0856306, -1.22739949, -0.89317712, 2.33823226, 1.42676897, -0.35371718, -1.53691283],
                    [1.6750938, -0.52670496, -2.05138179, 1.21962725, -0.01857794, 0.74726433, -0.40102479],
                    [0.0, -2.82717909, -1.18702174, -0.17157162, -0.88445462, 1.05407823, -1.89323985],
                    [0.0, 0.0, -2.67770649, -0.55778411, -0.73189524, 0.23038313, -0.55540004],
                    [0.0, 0.0, 0.0, 2.33558325, 0.39805554, -1.06620523, 0.23499938],
                    [0.0, 0.0, 0.0, 0.0, -1.7559906, -0.5339107, 0.38957697],
                    [0.0, 0.0, 0.0, 0.0, 0.0, 0.10395654, 3.02718803]
                ],
                [
                    [1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                    [0.0, -0.2560529, 0.29394307, -0.16437354, 0.39769085, -0.74679442, -0.32427734],
                    [0.0, -0.26504901, -0.36679003, 0.1845631, 0.20095002, -0.32726423, 0.78336949],
                    [0.0, 0.88993943, 0.15084829, -0.13337391, 0.25211649, -0.19394016, 0.25746551],
                    [0.0, -0.08361843, 0.7930035, 0.4028732, -0.32226788, -0.05342369, 0.3084411],
                    [0.0, -0.10365729, 0.19720641, 0.30282494, 0.79403082, 0.47732581, -0.01835669],
                    [0.0, -0.23335994, 0.29759437, -0.8167738, 0.05963902, 0.25862986, 0.34556486]
                ]
            ],
            [
                [
                    [-4.0, 4.0, -3.0, 2.0, -1.0, -1.0, 1.0, 3.0],
                    [-2.0, -1.0, -1.0, -1.0, 4.0, 2.0, 3.0, 2.0],
                    [-1.0, 2.0, 2.0, 2.0, -3.0, -1.0, 0.0, -1.0],
                    [-3.0, -4.0, 1.0, 4.0, 2.0, 4.0, -3.0, -4.0],
                    [-1.0, -3.0, -1.0, 0.0, 3.0, 2.0, -3.0, 0.0],
                    [-1.0, -1.0, 3.0, 2.0, 4.0, 2.0, 0.0, 0.0],
                    [3.0, -4.0, -4.0, 4.0, 4.0, 0.0, 4.0, 2.0],
                    [-3.0, 2.0, 4.0, 3.0, -3.0, 3.0, -3.0, 3.0]
                ],
                [
                    [-4.0, -2.57247878, -0.1394241, 4.21069107, 0.07200895, 0.45978292, -4.04795721, 0.17450307],
                    [5.83095189, 4.52941176, -1.67030715, 3.17801174, -1.127729, 3.75279014, -4.58086675, -2.11907807],
                    [0.0, 4.99255501, 0.85581764, 1.38424818, 0.25216862, 2.83083523, 1.10890185, -0.05937481],
                    [0.0, 0.0, -6.57939733, 1.83548773, -5.58330139, 3.5109269, 1.9269543, -0.37700605],
                    [0.0, 0.0, 0.0, 4.60906198, 7.04333021, -2.87531805, -3.2368298, -3.13111834],
                    [0.0, 0.0, 0.0, 0.0, 4.76321778, 2.37421728, 0.43959983, 1.22903426],
                    [0.0, 0.0, 0.0, 0.0, 0.0, 1.19563948, 1.72829629, -1.51439105],
                    [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.97670345, -1.36656092]
                ],
                [
                    [1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                    [0.0, -0.34299717, 0.41423102, 0.77576679, 0.28089884, -0.12386935, 0.00822052, -0.12097991],
                    [0.0, -0.17149859, -0.01616511, -0.33263192, 0.23173036, -0.57187833, 0.42011288, -0.54994938],
                    [0.0, -0.51449576, 0.19196072, -0.13279801, -0.67058596, -0.31893048, -0.3596074, 0.00949848],
                    [0.0, -0.17149859, -0.08486684, 0.16455908, -0.4784905, 0.51555312, 0.56509907, -0.34960125],
                    [0.0, -0.17149859, -0.29097204, 0.15771242, -0.08836387, -0.34318553, 0.51897994, 0.68273394],
                    [0.0, 0.51449576, -0.39806591, 0.46009371, -0.3417905, -0.38854675, -0.14384903, -0.27689269],
                    [0.0, -0.51449576, -0.73551265, 0.07916732, 0.25323758, 0.14613354, -0.29111927, -0.13346567]
                ]
            ],
            [
                [
                    [2.23814334, -0.23018456, 1.03453433, -0.03438708, -0.70409141, 2.58920678, 0.67945884, 0.51749154, -0.23515597, -1.27439696],
                    [1.31318787, -2.21974121, 1.79046563, -0.98284148, -1.04811065, 1.71721252, 0.50657415, -2.18514244, 0.26020407, 0.90970656],
                    [0.32372994, 1.04390874, -0.48189638, -0.56541353, 0.69498316, 1.15422812, -3.19832468, -1.54012241, -0.52484931, 1.20542977],
                    [-0.46465864, 0.58250329, 0.9731155, -0.05273145, -1.38155466, -2.56302474, 0.06284292, -1.49190396, 0.66722303, 0.21401172],
                    [0.97104696, -1.28966766, -0.08849259, -0.71327372, -1.93927983, -1.02559597, 0.64104262, 0.68867632, 0.18890576, -0.0288693],
                    [-0.83104099, -0.49990905, 0.2372282, -0.19119611, 1.05496154, -2.47815242, -3.29871356, 0.67468504, -0.20662392, 0.44474757],
                    [0.9759316, 2.38948286, -1.37150651, -1.6817551, -0.60416764, 0.88834346, -1.09923525, 0.32532695, 1.17197581, 2.00202573],
                    [-0.38594183, 1.55535715, -0.83515445, 0.12607541, -0.63293785, 0.07464177, 1.65657021, -0.23116537, 0.49585464, 0.41007326],
                    [-0.00598588, -1.00871989, -0.57349193, -1.04205841, -1.30197674, -0.36569647, 0.14714433, 0.42018829, 1.2513946, 1.24175751],
                    [0.77823347, -0.9801391, 0.08934166, -1.30002356, -0.01509173, 0.3179033, 1.96111845, -1.486749, 1.00714106, 1.33443445]
                ],
                [
                    [2.23814334, 1.42791741, -0.20888897, -2.01746515, -1.12466771, 0.4465626, 0.7194779, 0.26885338, 0.96522106, -1.26269023],
                    [-2.32073462, -0.49504797, -0.08743459, 1.43566982, 2.93925648, 2.76147506, 0.450575, -0.86469763, 0.91707241, 1.08781194],
                    [0.0, -2.70231238, -0.16434996, 0.34225826, 0.05994725, -1.66102203, 1.16368528, -0.31436128, -0.93699183, -1.70701051],
                    [0.0, 0.0, 3.2012163, -1.04432699, -2.13000213, 0.78559679, 0.58067726, -3.45184901, -0.68178964, -0.68399821],
                    [0.0, 0.0, 0.0, -3.0802468, -1.36864039, 1.5907966, 0.00856587, 0.0389714, -2.01700504, 0.328306],
                    [0.0, 0.0, 0.0, 0.0, 2.4315892, -0.34574838, 0.18263548, -1.45158483, 0.26936319, 0.06242084],
                    [0.0, 0.0, 0.0, 0.0, 0.0, -2.94924628, -0.50610645, -0.62573034, -1.19486675, 1.55907844],
                    [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.4929153, -0.94579752, -0.87955903, 2.82991928],
                    [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.6159741, -0.12887133, -0.91273885],
                    [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -0.67025053, -0.91748387]
                ],
                [
                    [1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                    [0.0, -0.56585008, -0.25979186, -0.10317256, 0.51194025, -0.12196159, 0.34673226, 0.01264491, 0.16951678, -0.41904744],
                    [0.0, -0.1394946, -0.03702878, -0.75425734, -0.03893428, 0.01269931, 0.13081243, 0.05632706, 0.26623937, 0.56340111],
                    [0.0, 0.2002205, 0.39266451, -0.01451981, 0.38848903, 0.45982743, 0.48201518, 0.28275552, -0.34851824, 0.09693423],
                    [0.0, -0.41842223, -0.25587355, 0.37679022, -0.28522623, 0.5512565, -0.0080546, 0.37347234, 0.21643407, 0.21413266],
                    [0.0, 0.35809393, -0.15159912, -0.26823174, -0.37910085, -0.0566067, 0.22791864, 0.5504669, 0.17296988, -0.49501223],
                    [0.0, -0.42052701, 0.47616297, -0.24700605, -0.48166238, 0.23336431, 0.06924889, -0.30785746, -0.17383355, -0.34520514],
                    [0.0, 0.16630158, 0.45730304, 0.22216467, 0.07127527, 0.03499574, 0.16298495, -0.16903031, 0.80718319, -0.02959155],
                    [0.0, 0.0025793, -0.1672858, 0.27391811, -0.35006573, -0.32729027, 0.7329571, -0.22885547, -0.12279428, 0.2502666],
                    [0.0, -0.33533928, 0.4739792, 0.14464118, -0.02795158, -0.55102837, -0.09863484, 0.54635062, -0.07288462, 0.15497312]
                ]
            ],
            [
                [
                    [-3.67379544, -3.78690518, -0.53785069, -4.59065863, -1.99483291, -0.90609587, -1.27480609, -1.60029829, 3.12570084, 0.28205526],
                    [0.53827107, -3.82793162, 2.84604818, -0.65413815, -4.22777272, -3.1818847, 0.21010875, -0.20665829, -1.86457509, -4.00330791],
                    [0.96552664, -2.51830113, 1.04340164, -1.94886354, 3.97304939, 0.82015328, 2.12492426, 1.83615475, 4.46620897, 4.13231256],
                    [-4.4874509, -1.19684517, 0.63856542, -3.6742626, 0.75135286, -1.77432252, 4.83927564, 0.75665818, 1.29727634, -0.98987724],
                    [2.44630063, -0.98814075, 2.65475124, 4.82431236, -3.31883233, -0.25405316, 0.48940484, -0.6389266, -2.03268702, -1.0643626],
                    [3.38081128, 1.51642561, 4.53896933, -0.22999773, 3.78893547, 2.92207783, -2.34642476, 2.62438274, 3.22736395, -1.4700763],
                    [4.74231976, 1.75233356, 1.99379648, -0.40403076, -4.30265083, 4.97980177, 1.3775096, -4.31847417, -3.53862963, 3.38913274],
                    [-2.2280509, 0.39450971, -4.19567227, 0.66346735, -1.37515089, -1.81786359, 1.53523262, -1.45096998, 2.15256807, 1.28281491],
                    [4.6751133, -2.18582476, -2.53604954, -4.22481646, 3.9207549, -4.65454981, -0.08524831, -4.9909544, 3.89198605, -1.60602529],
                    [1.30818196, -1.69293452, 3.88989739, 2.2932239, -4.05679226, 2.06701207, 3.80416664, 0.40537818, 4.75730844, -0.29996768]
                ],
                [
                    [-3.67379544, -2.38510625, -0.25407136, 3.31369441, -0.19899188, -3.9018674, 0.64103981, 0.07135938, 1.43388976, 4.4799564],
                    [-9.47603803, 1.25245055, 2.56412601, 0.56178927, -0.35137001, 0.58251419, 3.09369261, -3.5412232, 2.21925522, -1.23630537],
                    [0.0, 10.1063372, -0.65249874, -0.11296233, -2.12534984, 0.30065825, -5.33822792, -0.60241853, -1.4276178, -0.98202264],
                    [0.0, 0.0, 10.4167505, 0.09171814, 1.93054874, -0.1606046, 2.9376351, 2.03601298, -0.61515897, 4.40225362],
                    [0.0, 0.0, 0.0, 7.36966921, -3.23633073, 1.88784323, 3.86002553, 2.14680964, 2.64342331, 2.57959219],
                    [0.0, 0.0, 0.0, 0.0, -6.8521724, -0.87616151, -2.78382406, -1.52370273, 2.32267211, 3.25033804],
                    [0.0, 0.0, 0.0, 0.0, 0.0, 3.72625228, -1.3156165, -3.98401394, -1.58291166, 3.44293801],
                    [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 6.13397725, 2.02674832, 0.57257839, 0.20764846],
                    [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -4.23393158, -0.44906526, 4.9443796],
                    [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -0.57594552, -0.17823338]
                ],
                [
                    [1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                    [0.0, -0.05680339, 0.32002678, -0.1477114, 0.47131844, 0.47068507, -0.4998403, 0.02052379, 0.26349855, -0.33039225],
                    [0.0, -0.10189139, -0.54247734, -0.19650016, -0.23584607, -0.00803465, -0.19823588, 0.6526942, 0.32954693, -0.16470546],
                    [0.0, 0.47355771, -0.45895885, -0.05657538, 0.08552099, 0.56016533, 0.13044602, -0.05577317, -0.44863782, -0.13927437],
                    [0.0, -0.25815648, 0.40525113, -0.32562511, 0.02965145, 0.15799887, 0.54068528, 0.47968437, -0.29228974, -0.17140953],
                    [0.0, -0.35677477, -0.18100849, -0.0658706, 0.11290259, -0.38775024, -0.33426939, -0.10624975, -0.59068255, -0.44786226],
                    [0.0, -0.50045386, -0.09498485, -0.12837637, -0.52624702, 0.41104624, 0.09665514, -0.4666728, 0.13933211, -0.17778984],
                    [0.0, 0.23512473, -0.09105057, 0.0148631, 0.16617798, -0.27584232, 0.44331231, -0.20694802, 0.38789284, -0.66534727],
                    [0.0, -0.4933616, -0.31475677, 0.55641297, 0.47740407, 0.16936327, 0.26002148, 0.07963593, 0.06335532, 0.11559239],
                    [0.0, -0.13805157, -0.2815693, -0.70689519, 0.41088907, -0.12473977, 0.12763329, -0.2492377, 0.11164264, 0.35594393]
                ]
            ],
        ];
    }

    /**
     * @test         Hessenberg decomposition preserves eigenvalues: eigenvals(A) = eigenvals(H)
     * @dataProvider dataProviderForPreservesEigenvalues
     * @param        array $A
     * @throws       \Exception
     */
    public function testHessenbergDecompositionPreservesEigenvalues(array $A)
    {
        // Given
        $A = MatrixFactory::create($A);

        // When
        $hessenberg = $A->hessenbergDecomposition();

        // And
        $eigenvaluesA = $A->eigenvalues();
        $eigenvaluesH = $hessenberg->H->eigenvalues();

        // And sort for comparison
        sort($eigenvaluesA);
        sort($eigenvaluesH);

        // Then eigenvalues of A should equal eigenvalues of H
        $this->assertEqualsWithDelta($eigenvaluesA, $eigenvaluesH, 0.001);
    }

    /**
     * @return array (matrix, eigenvalues, dominant eigenvalue)
     */
    public function dataProviderForPreservesEigenvalues(): array
    {
        return [
            [
                [
                    [0, 0],
                    [0, 0],
                ],
            ],
            [
                [
                    [0, 1],
                    [-2, -3],
                ],
            ],
            [
                [
                    [6, -1],
                    [2, 3],
                ],
            ],
            [
                [
                    [1, -2],
                    [-2, 0],
                ],
            ],
            [
                [
                    [2, -12],
                    [1, -5],
                ],
            ],
            [
                [
                    [-2, -4, 2],
                    [-2, 1, 2],
                    [4, 2, 5],
                ],
            ],
            [
                [
                    [2, 0, 0],
                    [1, 2, 1],
                    [-1, 0, 1],
                ],
            ],
            [
                [
                    [1, 2, 1],
                    [6, -1, 0],
                    [-1, -2, -1],
                ],
            ],
            [
                [
                    [1, 2, 3],
                    [4, 5, 6],
                    [7, 8, 9],
                ],
            ],
            [
                [
                    [8, -6, 2],
                    [-6, 7, -4],
                    [2, -4, -3],
                ],
            ],
            [
                [
                    [0, 11, -5],
                    [-2, 17, -7],
                    [-4, 26, -10],
                ],
            ],
        ];
    }

    /**
     * @test Hessenberg decomposition handles high condition number matrices - robustness test
     *          - Hilbert matrices (ill-conditioned)
     *          - Matrix with very small entries (1e-12 scale)
     *          - Matrix with fractional entries for numerical precision
     * @dataProvider dataProviderForMatrixWithHighConditionNumbers
     * @param        array $A
     * @throws       \Exception
     */
    public function testHessenbergDecompositionHighConditionNumber(array $A)
    {
        // Given
        $A = MatrixFactory::create($A);

        // When
        $hessenberg = $A->hessenbergDecomposition();
        $QHQᵀ = $hessenberg->Q->multiply($hessenberg->H)->multiply($hessenberg->Q->transpose());

        // Then decomposition should still satisfy A = QHQ*
        $this->assertEqualsWithDelta($A->getMatrix(), $QHQᵀ->getMatrix(), 0.001);

        // And
        $this->assertTrue($hessenberg->Q->isOrthogonal());
        $this->assertTrue($hessenberg->H->isUpperHessenberg());
    }

    public function dataProviderForMatrixWithHighConditionNumbers(): array
    {
        return [
            // Hilbert matrix (notoriously ill-conditioned)
            [
                [
                    [1, 1/2, 1/3],
                    [1/2, 1/3, 1/4],
                    [1/3, 1/4, 1/5]
                ]
            ],
            // Matrix with very small entries
            [
                [
                    [1e-12, 2e-12, 3e-12],
                    [4e-12, 5e-12, 6e-12],
                    [7e-12, 8e-12, 9e-12]
                ]
            ],
            // Matrix with fractional entries
            [
                [
                    [1/2, 1/3, 1/4],
                    [1/5, 1/6, 1/7],
                    [2/3, 3/5, 8/9]
                ]
            ]
        ];
    }


    /**
     * @test         Hessenberg decomposition works on large matrices
     * @dataProvider dataProviderForLargeSquareMatrix
     * @param        array $A
     * @throws       \Exception
     */
    public function testHessenbergDecompositionLargeMatrices(array $A)
    {
        // Given
        $A = MatrixFactory::create($A);

        // When
        $hessenberg = $A->hessenbergDecomposition();
        $QHQᵀ = $hessenberg->Q->multiply($hessenberg->H)->multiply($hessenberg->Q->transpose());

        // Then
        $this->assertEqualsWithDelta($A->getMatrix(), $QHQᵀ->getMatrix(), 0.0001);

        // And
        $this->assertTrue($hessenberg->Q->isOrthogonal());
        $this->assertTrue($hessenberg->H->isUpperHessenberg());
    }

    /**
     * @test   Hessenberg decomposition handles mixed-scale matrices
     * @throws \Exception
     */
    public function testHessenbergDecompositionMixedScale()
    {
        // Given - matrix with entries spanning many orders of magnitude
        $A = MatrixFactory::create([
            [1e10, 1e-5, 1e2],
            [1e-8, 1e6, 1e-3],
            [1e4, 1e-10, 1e8]
        ]);

        // When
        $hessenberg = $A->hessenbergDecomposition();
        $QHQᵀ = $hessenberg->Q->multiply($hessenberg->H)->multiply($hessenberg->Q->transpose());

        // Then decomposition should still be valid despite extreme scaling
        $relativeError = $A->subtract($QHQᵀ)->frobeniusNorm() / $A->frobeniusNorm();
        $this->assertLessThan(1e-8, $relativeError);

        // And
        $this->assertTrue($hessenberg->Q->isOrthogonal());
        $this->assertTrue($hessenberg->H->isUpperHessenberg());
    }

    /**
     * @test         Hessenberg decomposition handles matrices with repeated eigenvalues
     * @dataProvider dataProviderForRepeatedEigenvalues
     * @param        array $A
     * @throws       \Exception
     */
    public function testHessenbergDecompositionRepeatedEigenvalues(array $A)
    {
        // Given - Jordan block matrix (repeated eigenvalue = 5)
        $A = MatrixFactory::create($A);

        // When
        $hessenberg = $A->hessenbergDecomposition();
        $QHQᵀ = $hessenberg->Q->multiply($hessenberg->H)->multiply($hessenberg->Q->transpose());

        // Then
        $this->assertEqualsWithDelta($A->getMatrix(), $QHQᵀ->getMatrix(), 0.0001);
        $this->assertTrue($hessenberg->Q->isOrthogonal());
        $this->assertTrue($hessenberg->H->isUpperHessenberg());
        $this->assertEqualsWithDelta($A->trace(), $hessenberg->H->trace(), 0.0001);
    }

    public function dataProviderForRepeatedEigenvalues(): array
    {
        return [
            // Jordan block matrix (repeated eigenvalue = 5)
            [
                [
                    [5, 1, 0, 0],
                    [0, 5, 1, 0],
                    [0, 0, 5, 1],
                    [0, 0, 0, 5]
                ]
            ],
            // Repeated eigenvalue but not Jordan form
            [
                [
                    [3, 0, 1],
                    [2, 3, 4],
                    [1, 0, 3]
                ]
            ],
        ];
    }

    /**
     * @test   Hessenberg decomposition edge cases with tiny entries
     * @throws \Exception
     */
    public function testHessenbergDecompositionTinyEntries()
    {
        // Given - matrix with entries near machine precision
        $epsilon = 1e-15;
        $A = MatrixFactory::create([
            [$epsilon, 2*$epsilon, 3*$epsilon],
            [4*$epsilon, 5*$epsilon, 6*$epsilon],
            [7*$epsilon, 8*$epsilon, 9*$epsilon]
        ]);

        // When
        $hessenberg = $A->hessenbergDecomposition();
        $QHQᵀ = $hessenberg->Q->multiply($hessenberg->H)->multiply($hessenberg->Q->transpose());

        // Then - should handle tiny values without breaking
        $relativeError = $A->subtract($QHQᵀ)->frobeniusNorm() / $A->frobeniusNorm();
        $this->assertLessThan(1e-10, $relativeError);
        $this->assertTrue($hessenberg->Q->isOrthogonal());
        $this->assertTrue($hessenberg->H->isUpperHessenberg());
    }

    /**
     * @test         Hessenberg decomposition strange cases
     * @dataProvider dataProviderForStrangeCases
     * @param        array $A
     * @throws       \Exception
     */
    public function testHessenbergDecompositionPathologicalCases(array $A)
    {
        // Given
        $A = MatrixFactory::create($A);

        // When
        $hessenberg = $A->hessenbergDecomposition();

        // Then
        $QHQ2 = $hessenberg->Q->multiply($hessenberg->H)->multiply($hessenberg->Q->transpose());
        $this->assertEqualsWithDelta($A->getMatrix(), $QHQ2->getMatrix(), 0.0001);
        $this->assertTrue($hessenberg->Q->isOrthogonal());
        $this->assertTrue($hessenberg->H->isUpperHessenberg());
    }

    public function dataProviderForStrangeCases(): array
    {
        return [
            // Matrix with nearly-zero subdiagonal entries
            [
                [
                    [1, 2, 3],
                    [1e-14, 4, 5],
                    [6, 7, 8]
                ]
            ],
            // Matrix that might cause Householder reflection issues
            [
                [
                    [1, 0, 0],
                    [1, 0, 0],
                    [0, 0, 1]
                ]
            ],
            // Symmetric with diagonals all the same
            [
                [
                    [2.0, 1.0, 1.0, 1.0],
                    [1.0, 2.0, 1.0, 1.0],
                    [1.0, 1.0, 2.0, 1.0],
                    [1.0, 1.0, 1.0, 2.0]
                ],
            ],
            // Already upper Hessenberg matrix - should be Q=I, H=A
            [
                [
                    [1, 2, 3, 4],
                    [5, 6, 7, 8],
                    [0, 9, 10, 11],
                    [0, 0, 12, 13]
                ]
            ],
            // Upper triangular matrix - special case of upper Hessenberg
            [
                [
                    [1, 2, 3],
                    [0, 4, 5],
                    [0, 0, 6]
                ]
            ],
            // Diagonal matrix - should be Q=I, H=A
            [
                [
                    [2, 0, 0],
                    [0, 3, 0],
                    [0, 0, 4]
                ]
            ],
            // Identity matrix - trivial case
            [
                [
                    [1, 0, 0],
                    [0, 1, 0],
                    [0, 0, 1]
                ]
            ],
            // Nearly singular matrix (very small determinant)
            [
                [
                    [1, 1, 1],
                    [1, 1, 1.0000001],
                    [1, 1.0000001, 1]
                ]
            ],
            // Matrix with extreme condition number
            [
                [
                    [1e6, 0, 0],
                    [1, 1e-6, 0],
                    [1, 1, 1]
                ]
            ],
            // Skew-symmetric matrix (A = -A^T)
            [
                [
                    [0, 1, -2],
                    [-1, 0, 3],
                    [2, -3, 0]
                ]
            ],
            // Matrix with repeated eigenvalues (should have multiple valid decompositions)
            [
                [
                    [2, 1, 0],
                    [0, 2, 1],
                    [0, 0, 2]
                ]
            ],
            // Matrix where first column element is very large (Householder instability case)
            [
                [
                    [1e12, 1, 1],
                    [1, 2, 3],
                    [1, 4, 5]
                ]
            ],
            // Matrix where first column has mixed large/small values
            [
                [
                    [1e-12, 1e6, 1e6],
                    [1e6, 1, 1],
                    [1e6, 1, 1]
                ]
            ],
            // Zero column below diagonal (should not require transformation)
            [
                [
                    [1, 2, 3],
                    [0, 4, 5],
                    [0, 0, 6]
                ]
            ],
            // Permutation matrix (orthogonal)
            [
                [
                    [0, 1, 0],
                    [0, 0, 1],
                    [1, 0, 0]
                ]
            ],
            // Matrix with alternating signs
            [
                [
                    [1, -1, 1],
                    [-1, 1, -1],
                    [1, -1, 1]
                ]
            ],
            // Companion matrix (important in eigenvalue problems)
            [
                [
                    [0, 1, 0],
                    [0, 0, 1],
                    [-6, -11, -6]
                ]
            ],
            // Block diagonal structure
            [
                [
                    [1, 2, 0, 0],
                    [3, 4, 0, 0],
                    [0, 0, 5, 6],
                    [0, 0, 7, 8]
                ]
            ],
            // Matrix with very small norm column (potential division by zero)
            [
                [
                    [1, 2, 3],
                    [1e-15, 4, 5],
                    [1e-15, 6, 7]
                ]
            ],
            // Matrix with all negative entries
            [
                [
                    [-1, -2, -3],
                    [-4, -5, -6],
                    [-7, -8, -9]
                ]
            ],
            // Larger symmetric matrix with special structure
            [
                [
                    [4, 1, 1, 1, 1],
                    [1, 4, 1, 1, 1],
                    [1, 1, 4, 1, 1],
                    [1, 1, 1, 4, 1],
                    [1, 1, 1, 1, 4]
                ]
            ],
            // Matrix with zero row/column patterns
            [
                [
                    [1, 0, 3],
                    [0, 2, 0],
                    [5, 0, 7]
                ]
            ]
        ];
    }

    /**
     * @test   Householder numerical stability - large positive first element could cause cancellation
     * @throws \Exception
     */
    public function testHouseholderNumericalInstabilityLargePositiveElement()
    {
        // Given
        $A = MatrixFactory::create([
            [1e15, 2, 3],
            [1, 4, 5],
            [1, 6, 7]
        ]);

        // When
        $hessenberg = $A->hessenbergDecomposition();

        // Then decomposition should satisfy A = QHQ*
        $QHQ = $hessenberg->Q->multiply($hessenberg->H)->multiply($hessenberg->Q->transpose());
        $this->assertEqualsWithDelta($A->getMatrix(), $QHQ->getMatrix(), 1e-10);
    }

    /**
     * @test   Householder numerical stability - multiple large positive elements
     * @throws \Exception
     */
    public function testHouseholderNumericalInstabilityMultipleLargeElements()
    {
        // Given matrix designed to trigger cancellation in multiple Householder steps
        $A = MatrixFactory::create([
            [1e14, 2, 3, 4],
            [5e13, 1e14, 7, 8],
            [1, 2, 1e14, 11],
            [1, 2, 3, 1e14]
        ]);

        // When
        $hessenberg = $A->hessenbergDecomposition();

        // Then decomposition should satisfy A = QHQ*
        $QHQ = $hessenberg->Q->multiply($hessenberg->H)->multiply($hessenberg->Q->transpose());
        // Use higher tolerance for very large numbers due to floating point precision limits
        $this->assertEqualsWithDelta($A->getMatrix(), $QHQ->getMatrix(), 0.1);
    }

    /**
     * @test    Householder orthogonality with problematic matrices
     * @throws  \Exception
     */
    public function testHouseholderOrthogonalityWithCancellationProne()
    {
        // Matrix that should produce a poorly conditioned Q due to cancellation
        $A = MatrixFactory::create([
            [1e15, 1e-15, 0],
            [1, 1e15, 1e-15],
            [0, 1, 1e15]
        ]);

        // When
        $hessenberg = $A->hessenbergDecomposition();

        // Then Q should be orthogonal: Q^T * Q = I, but cancellation could break this
        $I = MatrixFactory::identity(3);
        $QQ = $hessenberg->Q->transpose()->multiply($hessenberg->Q);
        $this->assertEqualsWithDelta($I->getMatrix(), $QQ->getMatrix(), 1e-14);
    }
}
